{"id":13547934,"url":"https://github.com/jamen/hyperapp-hmr","last_synced_at":"2025-09-25T01:31:02.558Z","repository":{"id":57270112,"uuid":"95391330","full_name":"jamen/hyperapp-hmr","owner":"jamen","description":"Persist the app state while the code reloads","archived":false,"fork":false,"pushed_at":"2017-06-26T18:41:21.000Z","size":22,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-12T11:43:42.199Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamen.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-25T23:25:25.000Z","updated_at":"2021-12-19T15:36:38.000Z","dependencies_parsed_at":"2022-09-01T06:30:52.717Z","dependency_job_id":null,"html_url":"https://github.com/jamen/hyperapp-hmr","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Fhyperapp-hmr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Fhyperapp-hmr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Fhyperapp-hmr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Fhyperapp-hmr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamen","download_url":"https://codeload.github.com/jamen/hyperapp-hmr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234143461,"owners_count":18786167,"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":[],"created_at":"2024-08-01T12:01:03.318Z","updated_at":"2025-09-25T01:31:02.234Z","avatar_url":"https://github.com/jamen.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"\n# hyperapp-hmr\n\n\u003e Persist the app state while the code reloads\n\nA [HyperApp](https://github.com/hyperapp/hyperapp) mixin that lets you perform [Hot Module Replacement](https://webpack.github.io/docs/hot-module-replacement.html) without needing any ties into your build mechanism.\n\n```js\nvar { h, app } = require('hyperapp')\nvar hmr = require('hyperapp-hmr')\n\napp({\n  // Simply load HMR as a mixin\n  mixins: [ hmr ],\n  \n  // The rest of your application stays unchanged, e.g. state:\n  state: { count: 0 },\n\n  // Try changing action's functionality as the app is running with HMR\n  // Then when you reload, the state is persisted and the functions are updated\n  actions: {\n    add: (state) =\u003e ({ count: state.count + 1 })\n  },\n\n  // Also change the view freely with the HMR\n  view: (state, actions) =\u003e\n    \u003cdiv class='app'\u003e\n      \u003cbutton onclick={actions.add}\u003eAdd one\u003c/button\u003e\n      \u003cspan\u003eCurrent value: {state.count}\u003c/span\u003e\n    \u003c/div\u003e\n})\n```\n\nTODO: Replace this example with a screen capture of the test\n\nSee [Usage](#usage) for more details, and [Testing](#testing) for seeing an example\n\n## Install\n\n```\nnpm i hyperapp-hmr\n```\n\n## Usage\n\nThe module exports an `hmr` mixin, which will persist all of the app's state between reloads, so the actions and views can change seamlessly underneath.\n\nTake an example: You go to a route on your page, open up a sidebar, click a button that opens a prompt, type in the prompt...  These are a lot of steps you have to repeat over and over without the state being persisted.  HMR solves this.\n\n### `hmr`\n\nThe mixin that you load into your app:\n\n```js\nvar hmr = require('hyperapp-hmr')\n\napp({\n  mixin: [ hmr ]\n})\n```\n\n### What about live-reloading?\n\nLive-reloading is not provided out of the box in `hyperapp-hmr` because:\n\n - There are standalone auto-reload servers you can opt-in to using with this package with no problems. For example, see [`budo`](https://npmjs.com/budo) for a prototyping tool that lets you live-reload _super easy_.\n - There may be people who are uninterested in what it takes to setup auto-reloading, and don't mind just hitting F5 with the same HMR benefits.\n - It would significantly increase the complexity of the package, as there would need to be a server-side so we could detect file changes, and communicate that to client-side for reloading, etc. which makes it less appealing to some.\n\n### Integration with Webpack?\n\nI personally main [Browserify](https://github.com/substack/node-browser), which is why there nothing made using [`module.hot`](https://webpack.github.io/docs/hot-module-replacement.html#api).\n\nThat being said, happy to accept PRs that can integrate those features with the same usage shown here.\n\n## Testing\n\nTo run the tests, clone the repository and run:\n\n```sh\nnpm i\nnpm run test:browser\n```\n\nThis will create temporary server that hosts and live-reloads `test/index.js`.\n\nGo into `test/index.js` and make edits to the view and actions see if the HMR is working.\n\n(Note: it is intentionally not `npm test` so release tools don't think they're unit tests)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamen%2Fhyperapp-hmr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamen%2Fhyperapp-hmr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamen%2Fhyperapp-hmr/lists"}