{"id":28633661,"url":"https://github.com/nallwhy/life_cycle_hook","last_synced_at":"2025-06-12T15:09:34.066Z","repository":{"id":43481961,"uuid":"451474551","full_name":"nallwhy/life_cycle_hook","owner":"nallwhy","description":"A Phoenix LiveView hook for watching life-cycle of a LiveView","archived":false,"fork":false,"pushed_at":"2022-02-28T13:41:31.000Z","size":53,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-11T03:41:14.846Z","etag":null,"topics":["elixir","elixir-library"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nallwhy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-24T13:26:33.000Z","updated_at":"2024-08-24T01:00:00.000Z","dependencies_parsed_at":"2022-09-12T01:01:12.068Z","dependency_job_id":null,"html_url":"https://github.com/nallwhy/life_cycle_hook","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nallwhy/life_cycle_hook","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nallwhy%2Flife_cycle_hook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nallwhy%2Flife_cycle_hook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nallwhy%2Flife_cycle_hook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nallwhy%2Flife_cycle_hook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nallwhy","download_url":"https://codeload.github.com/nallwhy/life_cycle_hook/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nallwhy%2Flife_cycle_hook/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259490550,"owners_count":22865769,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","elixir-library"],"created_at":"2025-06-12T15:09:30.794Z","updated_at":"2025-06-12T15:09:34.053Z","avatar_url":"https://github.com/nallwhy.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LifeCycleHook\n\n[![Hex Version](https://img.shields.io/hexpm/v/life_cycle_hook.svg)](https://hex.pm/packages/life_cycle_hook)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/life_cycle_hook/)\n[![Total Download](https://img.shields.io/hexpm/dt/life_cycle_hook.svg)](https://hex.pm/packages/life_cycle_hook)\n[![License](https://img.shields.io/hexpm/l/life_cycle_hook.svg)](https://github.com/nallwhy/life_cycle_hook/blob/master/LICENSE.md)\n[![Last Updated](https://img.shields.io/github/last-commit/nallwhy/life_cycle_hook.svg)](https://github.com/nallwhy/life_cycle_hook/commits/main)\n\n\u003c!-- MDOC !--\u003e\n\nLifeCycleHook is a simple hook that logs each life-cycle stage of LiveView.\n\nIt is good for learning Phoenix LiveView life-cycle.\n\n## Overview\n\nBy mounting `LifeCycleHook` on LiveView with `use LifeCycleHook`, you can see logs for each life-cycle of LiveView.\n\n```elixir\ndefmodule MyApp.MyLive do\n  use Phoenix.LiveView\n  use LifeCycleHook\n\n  @impl true\n  def render(assigns) do\n    ...\n  end\n\n  @impl true\n  def handle_event(\"click\", params, socket) do\n    ...\n  end\n\n  @impl true\n  def handle_info(:send, socket) do\n    ...\n  end\nend\n```\n\n```\n[debug] MyApp.MyLive mount connected: false\n[debug] MyApp.MyLive handle_params connected: false\n[debug] MyApp.MyLive mount connected: true\n[debug] MyApp.MyLive handle_params connected: true\n\n[debug] MyApp.MyLive handle_event event: click\n[debug] MyApp.MyLive handle_info message: send\n```\n\n### only/except options\n\nIf you want to choose specific stages to log, you can use `only` or `except` option in `use LifeCycleHook`.\nFor example, you can set `only: [:mount]` option to use `LifeCycleHook` in sticky nested LiveView which doesn't support `handle_params` hook.\n\n```elixir\ndefmodule MyApp.MyStickyNestedLive do\n  use Phoenix.LiveView\n  use LifeCycleHook, only: [:mount]\n\n  @impl true\n  def render(assigns) do\n    ...\n  end\nend\n```\n\n```\n[debug] MyApp.MyStickyNestedLive mount connected: false\n[debug] MyApp.MyStickyNestedLive mount connected: true\n```\n\n### log_level option\n\nYou can change log level of `LifeCycleHook` with `log_level` option.\n\n```elixir\ndefmodule MyApp.MyWarnLogLevelLive do\n  use Phoenix.LiveView\n  use LifeCycleHook, log_level: :warn\n\n  @impl true\n  def render(assigns) do\n    ...\n  end\nend\n```\n\n```\n[warning] MyApp.MyWarnLogLevelLive mount connected: false\n[warning] MyApp.MyWarnLogLevelLive mount connected: true\n```\n\n## Installation\n\nThe package can be installed by adding `:life_cycle_hook` to your list of\ndependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:life_cycle_hook, \"~\u003e 0.8\"}\n  ]\nend\n```\n\u003c!-- MDOC !--\u003e\n\n## TO DO\n\n- [x] Add `handle_params` hook\n- [x] Add macro that replace `on_mount({LifeCycleHook, __MODULE__})`\n- [ ] Support nested LiveView with `sticky: true` option\n- [x] Add `handle_event` hook\n- [x] Add `handle_info` hook\n- [x] Support `only`, `except` options in `use LifeCycleHook`\n- [x] Support setting log level\n- [ ] Support watching params of each hook\n- [ ] Support LiveComponent\n- [x] Remove `Elixir` prefix from module names in logs\n\n## Copyright and License\n\nCopyright (c) 2022 Jinkyou Son (Json)\n\nThis work is free. You can redistribute it and/or modify it under the\nterms of the MIT License. See the [LICENSE.md](./LICENSE.md) file for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnallwhy%2Flife_cycle_hook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnallwhy%2Flife_cycle_hook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnallwhy%2Flife_cycle_hook/lists"}