{"id":16642000,"url":"https://github.com/artskydj/virtualdom-state-renderer","last_synced_at":"2026-04-20T18:31:47.053Z","repository":{"id":28138288,"uuid":"31637876","full_name":"ArtskydJ/virtualdom-state-renderer","owner":"ArtskydJ","description":"Use Matt-Esch/virtual-dom with TehShrike/abstract-state-router!","archived":false,"fork":false,"pushed_at":"2016-01-02T17:10:00.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-25T05:21:13.540Z","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/ArtskydJ.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":"2015-03-04T04:26:58.000Z","updated_at":"2016-02-05T20:48:34.000Z","dependencies_parsed_at":"2022-08-27T02:19:14.796Z","dependency_job_id":null,"html_url":"https://github.com/ArtskydJ/virtualdom-state-renderer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtskydJ%2Fvirtualdom-state-renderer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtskydJ%2Fvirtualdom-state-renderer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtskydJ%2Fvirtualdom-state-renderer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArtskydJ%2Fvirtualdom-state-renderer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ArtskydJ","download_url":"https://codeload.github.com/ArtskydJ/virtualdom-state-renderer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243165134,"owners_count":20246720,"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-10-12T07:48:34.180Z","updated_at":"2026-04-20T18:31:47.013Z","avatar_url":"https://github.com/ArtskydJ.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"virtualdom-state-renderer\n=========================\n\n\u003e Use [virtual-dom][v-dom] with [abstract-state-router][asr]!\n\n# example\n\n*index.js*\n```js\nvar StateRouter = require('abstract-state-router')\nvar virtualdomRenderer = require('virtualdom-state-renderer')\nvar domready = require('domready')\n\nvar stateRouter = StateRouter(virtualdomRenderer, 'body')\n\n// add whatever states to the state router\nstateRouter.addState({\n\tname: 'app',\n\troute: '/',\n\ttemplate: require('./template.js')\n})\n\ndomready(function() {\n\tstateRouter.evaluateCurrentRoute('app')\n})\n```\n\n*template.js*\n```js\nmodule.exports = function template(h, resolveContent, helpers) {\n\treturn (\n\t\th('div', [\n\t\t\th('p', 'Pretty sweet, isn\\'t it?'),\n\t\t\th('p', 'Here, let me give some examples or something.')\n\t\t])\n\t)\n}\n```\n\n# api\n\n```js\nvar virtualdomRenderer = require('virtualdom-state-renderer')\n```\n\n## `virtualdomRenderer`\n\nPass this object into the `StateRouter`.\n\n```js\nvar Router = require('abstract-state-router')\nvar renderer = require('virtualdom-state-renderer')\n\nRouter(renderer, 'body')\n```\n\n## templates\n\nA template is a function that returns a `virtual-dom` object. If you wanted, you could use the [`virtual-html`][v-html] library to generate a `virtual-dom` object.\n\nThe function is supplied with these arguments:\n- `h` is a function that returns a `virtual-dom` node. [View API here][v-hyperscript].\n- `resolveContent` is the resolve content, which is the set in the resolve callback. See the [`resolve()` function docs][asr-resolve].\n- `helpers` is an object with the following properties:\n\t- `var active = isActive(stateName, parameters)` is a reference to [`stateRouter.stateIsActive(stateName, parameters)`][asr-stateisactive]. Returns `true` or `false`.\n\t- `var class = active(stateName, parameters)` is an abstraction to [`stateRouter.stateisActive(stateName, parameters)`][asr-stateisactive]. Returns `'active'` or `''`.\n\t- `var url = makePath(stateName, parameters)` is a reference to [`stateRouter.makePath(stateName, parameters)`][asr-makepath]. This function returns a URL for the given state and parameters.\n\t- `killEvent(ev)` is a function that does `ev.preventDefault()` and `ev.stopPropagation()`.\n\t- `emitter` is the event emitter that is on the `domApi`. This allows a bit of communication between the template's DOM events (e.g. a mouse-click), and the [`activate()` function][asr-activate].\n\ntemplate.js\n```js\nvar virtualHtml = require('virtual-html')\n\nmodule.exports = function template(h, resolveContent, helpers) {\n\tvar html = (\n\t\t'\u003cdiv\u003e' +\n\t\t\t'\u003cp\u003ePretty sweet, isn\\'t it?\u003c/p\u003e' +\n\t\t\t'\u003cp\u003eHere, let me give some examples or something.\u003c/p\u003e' +\n\t\t\t'\u003ca href=\"' + helpers.makePath('app') + '\"\u003e' +\n\t\t\t\t'Click to go to the \"app\" state.' +\n\t\t\t'\u003c/a\u003e' +\n\t\t'\u003c/div\u003e'\n\t)\n\treturn virtualHtml(html)\n}\n```\n\n## `domApi`\n\nThis object is exposed by the state router in the [`activate()` function][asr-activate]. The object has the following properties:\n\n- `el` is the DOM element that is created/updated.\n- `emitter` is the event emitter on `helpers`. This allows the template to request an update, or something.\n- `sharedState` is the object that comes from the resolve content, which is the set in the resolve callback. See the [`resolve()` function docs][asr-resolve].\n- `update()` is a function that will render the template, and update the DOM if necessary.\n\n# license\n\n[VOL][vol]\n\n[asr]: https://github.com/TehShrike/abstract-state-router\n[asr-activate]: https://github.com/TehShrike/abstract-state-router#activatecontext\n[asr-makepath]: https://github.com/TehShrike/abstract-state-router/blob/master/index.js#L213\n[asr-resolve]: https://github.com/TehShrike/abstract-state-router#resolvedata-parameters-callbackerr-contentredirectstatename-params\n[asr-stateisactive]: https://github.com/TehShrike/abstract-state-router/blob/master/index.js#L240\n[v-dom]: https://github.com/Matt-Esch/virtual-dom\n[v-html]: https://github.com/azer/virtual-html\n[v-hyperscript]: https://github.com/Matt-Esch/virtual-dom/blob/master/virtual-hyperscript/README.md\n[vol]: http://veryopenlicense.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartskydj%2Fvirtualdom-state-renderer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartskydj%2Fvirtualdom-state-renderer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartskydj%2Fvirtualdom-state-renderer/lists"}