{"id":20497181,"url":"https://github.com/alexcambose/virtual-dom","last_synced_at":"2025-06-22T07:05:25.412Z","repository":{"id":57096357,"uuid":"131417907","full_name":"alexcambose/virtual-dom","owner":"alexcambose","description":"A Virtual DOM algorithm implementation that improves front end performance by updating only changed nodes in the DOM.","archived":false,"fork":false,"pushed_at":"2019-12-29T23:22:13.000Z","size":160,"stargazers_count":13,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-16T14:14:59.169Z","etag":null,"topics":["algorithm","api","diffing","dom","dom-builder","dom-element","dom-events","dom-manipulation","dom-node","dom-tree","hyperscript","json","lightweight","object","optimization","react","virtual-dom"],"latest_commit_sha":null,"homepage":"https://alexcambose.github.io/virtual-dom/","language":"JavaScript","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/alexcambose.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-28T14:46:07.000Z","updated_at":"2024-08-30T01:55:31.000Z","dependencies_parsed_at":"2022-08-22T21:40:46.741Z","dependency_job_id":null,"html_url":"https://github.com/alexcambose/virtual-dom","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alexcambose/virtual-dom","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexcambose%2Fvirtual-dom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexcambose%2Fvirtual-dom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexcambose%2Fvirtual-dom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexcambose%2Fvirtual-dom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexcambose","download_url":"https://codeload.github.com/alexcambose/virtual-dom/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexcambose%2Fvirtual-dom/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260933089,"owners_count":23084933,"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":["algorithm","api","diffing","dom","dom-builder","dom-element","dom-events","dom-manipulation","dom-node","dom-tree","hyperscript","json","lightweight","object","optimization","react","virtual-dom"],"created_at":"2024-11-15T18:10:16.202Z","updated_at":"2025-06-22T07:05:20.399Z","avatar_url":"https://github.com/alexcambose.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# virtual-dom\n\n[![Build Status](https://travis-ci.org/alexcambose/virtual-dom.svg?branch=master)](https://travis-ci.org/alexcambose/virtual-dom)\n\nA Virtual DOM algorithm implementation that improves front end performance by updating only changed nodes in the DOM.\n\n### [**DEMO**](https://alexcambose.github.io/virtual-dom/)\n\n## Installation\nAs [npm](https://www.npmjs.com/package/@alexcambose/virtual-dom) package\n```bash\nnpm i -S @alexcambose/virtual-dom\n```\nStandalone script file\n```html\n\u003cscript src=\"dist/virtual-dom.js\"\u003e\u003c/script\u003e\n```\n\n## Usage\n```javascript\nlet newContent = null;\n\n// the function that will create virtual-dom object\nconst createDom = title =\u003e (\n    h('div', null,\n        h('h1', { className: 'header' }, title),\n        h('p', null , 'Lorem ipsum'),\n        h('footer', { className: 'footer' }, 'The footer'),\n    )\n);\n\n// create virtual-dom object\nlet content = createDom('Some title');\n\n// render the virtual dom object into the real dom\nrender(content, document.getElementById('app'));\n\nconst rerender = () =\u003e {\n\n    // create the virtual-dom object again but with dfferent properties\n    newContent = createDom('Some other title');\n\n    // patches object that will be used to modify changed elements\n    const patches = diff(content, newContent);\n\n    //appy patches\n    patch(appContainer, patches);\n\n    // update content\n    content = newContent;\n};\n```\n\n\n## API\n* `h(tagName, props, ...children)` - Function to define virtual-dom using hyperscript style\n```js\nh('div', { className: 'section' },\n    h('h1', { style: {color: 'red'} }, 'Section title'),\n));\n```\nwill output\n```js\n{\n   type: \"div\",\n   props: {\n      className: \"section\",\n      children: [\n         {\n            type: \"h1\",\n            props: {\n               style: {\n                  color: \"red\"\n               },\n               children: [\n                  \"Section title\"\n               ]\n            }\n         }\n      ]\n   }\n}\n```\n\n* `render(VDOM, domElement)` - renders the virtual dom object into a specified element in dom\n```js\n// content = h(..., h(...))\nrender(content, document.getElementById('app'));\n```\n* `diff(oldVDOM, newVDOM)` - create a *patches object* that contains all the differences between two virtual-dom objects, should be used with `patch`\n```js\nconst oldVDOM = h('h1', null, 'Hello title');\nconst newVDOM = h('h1', { className: 'header' }, 'Hello new class');\nconst patches = diff(oldVDOM, newVDOM);\n```\n`patches` will look something like this\n```js\n{\n   0:{\n      childrenPatches: {\n         0: {\n            selfPatch: {\n               type: PATCH_TEXT_NODE,\n               payload: \"Hello new class\"\n            }\n         }\n      }\n   }\n}\n```\n\n* `patch(domElement, patches)` - updates the dom based on the patches produced by `diff`\n```js\nconst patches = diff(oldVDOM, newVDOM);\npatch(document.getElementById('app'), patches);\n```\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexcambose%2Fvirtual-dom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexcambose%2Fvirtual-dom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexcambose%2Fvirtual-dom/lists"}