{"id":13438181,"url":"https://github.com/Olical/react-faux-dom","last_synced_at":"2025-03-19T18:32:18.618Z","repository":{"id":55825838,"uuid":"42004446","full_name":"Olical/react-faux-dom","owner":"Olical","description":"DOM like structure that renders to React (unmaintained, archived)","archived":true,"fork":false,"pushed_at":"2020-09-07T11:33:26.000Z","size":664,"stargazers_count":1206,"open_issues_count":0,"forks_count":87,"subscribers_count":25,"default_branch":"master","last_synced_at":"2024-05-17T04:43:53.045Z","etag":null,"topics":["d3","dom","javascript","react"],"latest_commit_sha":null,"homepage":"http://oli.me.uk/2015/09/09/d3-within-react-the-right-way/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Olical.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","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-09-06T13:57:24.000Z","updated_at":"2024-02-23T19:57:18.000Z","dependencies_parsed_at":"2022-08-15T07:30:57.338Z","dependency_job_id":null,"html_url":"https://github.com/Olical/react-faux-dom","commit_stats":null,"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Olical%2Freact-faux-dom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Olical%2Freact-faux-dom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Olical%2Freact-faux-dom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Olical%2Freact-faux-dom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Olical","download_url":"https://codeload.github.com/Olical/react-faux-dom/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221729820,"owners_count":16871116,"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":["d3","dom","javascript","react"],"created_at":"2024-07-31T03:01:03.468Z","updated_at":"2025-03-19T18:32:18.608Z","avatar_url":"https://github.com/Olical.png","language":"JavaScript","funding_links":[],"categories":["Uncategorized","Utilities"],"sub_categories":["Uncategorized","Miscellaneous"],"readme":"# react-faux-dom [![npm version](https://badge.fury.io/js/react-faux-dom.svg)](http://badge.fury.io/js/react-faux-dom) [![CDNJS](https://img.shields.io/cdnjs/v/react-faux-dom.svg)](https://cdnjs.com/libraries/react-faux-dom) [![Build Status](https://travis-ci.org/Olical/react-faux-dom.svg?branch=master)](https://travis-ci.org/Olical/react-faux-dom) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard) [![Join the chat at https://gitter.im/Olical/react-faux-dom](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Olical/react-faux-dom?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nDOM like data structure to be mutated by [D3][] et al, then rendered to [React][] elements.\n\nReactFauxDOM supports a wide range of DOM operations and will fool most libraries but it isn't exhaustive (the full DOM API is ludicrously large). It supports enough to work with D3 but will require you to fork and add to the project if you encounter something that's missing.\n\nYou can think of this as a bare bones [jsdom][] that's built to bridge the gap between the declarative React and the imperative JavaScript world. We just need to expand it as we go along since jsdom is a huge project that solves different problems.\n\nI'm trying to keep it light so as not to slow down your render function. I want efficient, declarative and stateless code, but I don't want to throw away previous tools to get there.\n\n## Example\n\n### Default\n\nThis style of calling `createElement` and `toReact` is the default API, it's easy to use and fits into the normal React flow but won't allow you to perform animations or D3 force layouts, for example.\n\n```javascript\nclass SomeChart extends React.Component {\n  render () {\n    // Create your element.\n    var el = ReactFauxDOM.createElement('div')\n\n    // Change stuff using actual DOM functions.\n    // Even perform CSS selections!\n    el.style.setProperty('color', 'red')\n    el.setAttribute('class', 'box')\n\n    // Render it to React elements.\n    return el.toReact()\n  }\n}\n\n// Yields: \u003cdiv style='color: red;' class='box'\u003e\u003c/div\u003e\n```\n\n### With animation helper\n\nComplex usage with [D3][], ES6 modules and animations. Clone it from [here][minimal-example-source], or try on in [codesandbox][minimal-example-sandbox].\n\n```javascript\nimport React from 'react'\nimport * as d3 from 'd3'\nimport {withFauxDOM} from 'react-faux-dom'\n\nclass MyReactComponent extends React.Component {\n  componentDidMount () {\n    const faux = this.props.connectFauxDOM('div', 'chart')\n    d3.select(faux)\n      .append('div')\n      .html('Hello World!')\n    this.props.animateFauxDOM(800)\n  }\n\n  render () {\n    return (\n      \u003cdiv\u003e\n        \u003ch2\u003eHere is some fancy data:\u003c/h2\u003e\n        \u003cdiv className='renderedD3'\u003e\n          {this.props.chart}\n        \u003c/div\u003e\n      \u003c/div\u003e\n    )\n  }\n}\n\nMyReactComponent.defaultProps = {\n  chart: 'loading'\n}\n\nexport default withFauxDOM(MyReactComponent)\n```\n\n## Limitations\n\nThis library is intended to be used to build a React DOM tree from some mutable intermediate value which is then thrown away inside a `render` function. This means things that require mutation of the DOM, such as D3's animations, zooming, dragging and brushing will not work.\n\nStatic charts will work fine out of the box, you can use this tool to translate SVG tools into DOM managed by React easily. If you wish to start adding in animations you'll have to use the `withFauxDOM` higher order component mentioned above and in a few of the examples.\n\nBefore you go to use this tool, stop and think:\n\n * Am I trying to build static DOM within a render method? - This is fine.\n * Am I trying to hook up timers and event listeners with a 3rd party tool to manipulate some DOM after I have inserted it into the page? - This is not going to work.\n\n## Installation\n\nYou can install the package `react-faux-dom` from npm as you usually would. Then use webpack or browserify (etc) to bundle the source into your build. If you need a pre-built UMD version you can use [unpkg][].\n\nYou can find the latest version of the UMD version at https://unpkg.com/react-faux-dom/dist/ReactFauxDOM.min.js\n\n### Independent documents\n\nBy default all Elements share an emulated `window` at \n`el.ownerDocument.defaultView` you can create independent documents with:\n\n```javascript\nimport React from 'react'\nimport rfdFactory from 'react-faux-dom/lib/factory'\n\nfunction getParagraph() {\n  const ReactFauxDOM = rfdFactory();\n  return new ReactFauxDOM.Element('p', someDiv);\n}\n\nconst p1 = getParagraph();\nconst p2 = getParagraph();\n\nassert(p1.ownerDocument !== p2.ownerDocument);\n```\n\n### More usage info:\n\n * Full [documentation][] with current DOM API coverage\n * An example static chart ([source][lab-chart-source], [article][lab-chart])\n * An \"hello world\" example using the HOC ([source][minimal-example-source], [sandbox][minimal-example-sandbox])\n * An example animated chart using the HOC ([source][hoc-animate-example], [sandbox][hoc-animate-sandbox])\n * An example chart with D3 updates using the HOC ([source][hoc-update-example], [sandbox][hoc-update-sandbox])\n * A simple example using state and events ([source][lab-state-source], [article][lab-state])\n * A d3 sankey diagram builder ([source][sankey-app-source], [demo][sankey-app])\n * `d3-react-sparkline`, a small component I built at [Qubit][] ([source][d3-react-sparkline])\n * `component-kit`, \"UI-Kit for Rapidly Creating Dashboards\" ([source][component-kit])\n * A demo dashboard with multiple charts ([source][rd3-source], [demo][rd3-demo])\n\n### Related articles:\n\n * [D3 within React the right way][Olical-post]\n * [React + D3.js: Balancing Performance \u0026 Developer Experience][tibotiber-post]\n * [A starting point on using D3 with React][AdilBaaj-post]\n\n## Development\n\n```bash\n# Fetch the dependencies\nmake bootstrap\n\n# Test\nmake test\n\n# Test continually\nmake test-watch\n```\n\n## Maintainers\n\nThis project is actively maintained by the following developers. Feel free to reach out if you'd like to join us and help out!\n\n * [@Olical](https://github.com/Olical)\n * [@tibotiber](https://github.com/tibotiber)\n\n## Unlicenced\n\nFind the full [unlicense][] in the `UNLICENSE` file, but here's a snippet.\n\n\u003eThis is free and unencumbered software released into the public domain.\n\u003e\n\u003eAnyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.\n\nDo what you want. Learn as much as you can. Unlicense more software.\n\n[unlicense]: http://unlicense.org/\n[d3]: http://d3js.org/\n[react]: http://facebook.github.io/react/\n[jsdom]: https://github.com/tmpvar/jsdom\n[lab-chart]: http://lab.oli.me.uk/d3-to-react-again/\n[lab-chart-source]: https://github.com/Olical/lab/blob/gh-pages/js/d3-to-react-again/main.js\n[lab-state]: http://lab.oli.me.uk/react-faux-dom-state/\n[lab-state-source]: https://github.com/Olical/lab/blob/gh-pages/js/react-faux-dom-state/main.js\n[d3-react-sparkline]: https://github.com/QubitProducts/d3-react-sparkline\n[qubit]: http://www.qubit.com/\n[documentation]: ./DOCUMENTATION.md\n[react-motion]: https://github.com/chenglou/react-motion\n[sankey-app]: http://nick.balestra.ch/sankey/\n[sankey-app-source]: https://github.com/nickbalestra/sankey\n[hoc-animate-example]: https://github.com/tibotiber/rfd-animate-example\n[hoc-animate-sandbox]: https://codesandbox.io/s/github/tibotiber/rfd-animate-example/tree/master/\n[hoc-update-example]: https://github.com/tibotiber/rfd-update-example\n[hoc-update-sandbox]: https://codesandbox.io/s/github/tibotiber/rfd-update-example/tree/master/\n[component-kit]: https://github.com/kennetpostigo/component-kit\n[unpkg]: https://unpkg.com/\n[Olical-post]: http://oli.me.uk/2015/09/09/d3-within-react-the-right-way/\n[tibotiber-post]: https://medium.com/@tibotiber/react-d3-js-balancing-performance-developer-experience-4da35f912484\n[rd3-demo]: https://rd3.now.sh\n[rd3-source]: https://github.com/tibotiber/rd3\n[AdilBaaj-post]: https://blog.sicara.com/a-starting-point-on-using-d3-with-react-869fdf3dfaf\n[minimal-example-source]: https://github.com/tibotiber/rfd-min-example\n[minimal-example-sandbox]: https://codesandbox.io/s/github/tibotiber/rfd-min-example/tree/master/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOlical%2Freact-faux-dom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FOlical%2Freact-faux-dom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOlical%2Freact-faux-dom/lists"}