{"id":20614756,"url":"https://github.com/dashed/orwell","last_synced_at":"2025-07-17T15:35:01.640Z","repository":{"id":32521307,"uuid":"36102574","full_name":"dashed/orwell","owner":"dashed","description":"Update React components whenever Probe cursors change","archived":false,"fork":false,"pushed_at":"2015-10-01T14:11:27.000Z","size":228,"stargazers_count":0,"open_issues_count":6,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-04T07:08:07.870Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dashed.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":"2015-05-23T01:31:31.000Z","updated_at":"2015-05-25T01:35:06.000Z","dependencies_parsed_at":"2022-06-26T23:09:55.925Z","dependency_job_id":null,"html_url":"https://github.com/dashed/orwell","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/dashed/orwell","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashed%2Forwell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashed%2Forwell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashed%2Forwell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashed%2Forwell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dashed","download_url":"https://codeload.github.com/dashed/orwell/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashed%2Forwell/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265623048,"owners_count":23800092,"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-11-16T11:13:31.848Z","updated_at":"2025-07-17T15:35:01.615Z","avatar_url":"https://github.com/dashed.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# orwell\n\n\u003e `orwell` is a higher-order component that can listen to [Probe](https://github.com/Dashed/probe) cursors for changes, and re-renders the wrapped component whenever any cursor emits a change.\n\n## Usage\n\n```\n$ npm install --save orwell\n```\n\n```js\nconst OrwellWrapped = orwell(Component, {\n\n    // any of these orwell lifecycle functions are optional\n\n    watchCursors(props, manual, context) {\n\n        const {cursor, otherCursor} = props;\n\n        // add validation step to decide to re-render OrwellWrapped\n        manual(function(update) {\n            const unsubscribe = otherCursor.on(event, function(newValue, oldValue) {\n\n                if(condition) {\n                    update();\n                }\n            });\n\n            // return a cleanup step; this will be called whenever OrwellWrapped unmounts\n            return unsubscribe;\n        });\n\n        // return an array of cursors to be observed.\n        // whenever these cursors emit an event, OrwellWrapped will re-render.\n        return [cursor];\n\n        // or return a single cursor directly; sugar to [cursor]\n        return cursor;\n    },\n\n    shouldRewatchCursors(props, context) {\n\n        // this is called whenever a subscribed cursor emits an event, or when the parent component renders.\n        // \n        // in the former case: props === this.props and context === this.context\n        // in the latter case: props === nextProps and context === nextContext (passed via parent component)\n        //\n        // these props and context are then passed to watchCursors(props, manual, context)\n\n        // return false by default\n        \n        // if return true, then watchCursors(props, manual, context) is called with appropriate props and context.\n    },\n\n    assignNewProps(props, context) {\n\n        const {valueCursor} = props;\n\n        // return a plain object which will be merged with this.props (whenever a subscribed cursor emits)\n        // or nextProps (when the parent component renders).\n        return {\n            value: valueCursor.deref()\n        };\n    },\n\n    shouldAssignNewProps(props, context) {\n\n        // this is called whenever a subscribed cursor emits an event, or when the parent component renders.\n        // \n        // in the former case: props === this.props and context === this.context\n        // in the latter case: props === nextProps and context === nextContext (passed via parent component)\n        // \n        // these props and context are then passed to assignNewProps(props, context)\n\n        // returns true by default\n        \n        // if return true, then watchCursors(props, manual, context) is called with appropriate props and context.\n    }\n\n});\n\n// static methods\n\n// set custom shouldComponentUpdate(nextProps, nextState).\n// returns same wrapped component\nconst OrwellWrapped2 = OrwellWrapped.shouldComponentUpdate(customShouldComponentUpdate);\n\n// sets shouldComponentUpdate(nextProps, nextState) to perform shallow equal on props. \n// any two Probe cursors it compares are compared as currentProbe.deref() === nextProbe.deref()\n// returns same wrapped component\nconst OrwellWrapped3 = OrwellWrapped.shallow();\n\n// sets shouldComponentUpdate(nextProps, nextState) to perform deep equal on props.\n// any two Probe cursors it compares are compared as currentProbe.deref() === nextProbe.deref()\n// returns same wrapped component\nconst OrwellWrapped4 = OrwellWrapped.deep();\n\n// inject object to be merged with component spec of the OrwellWrapped component\n// returns newly wrapped component\nconst OrwellWrapped4 = OrwellWrapped.inject({\n    // the only time to do this is passing `contextTypes` to access `context` from the orwell lifecycle methods\n    contextTypes: {\n        context: React.PropTypes.object.isRequired\n    }\n});\n\n// enable debug mode\n// returns same wrapped component\nconst OrwellWrapped5 = OrwellWrapped.debug();\nconst OrwellWrapped6 = OrwellWrapped.debug(true); // enable\nconst OrwellWrapped7 = OrwellWrapped.debug(false); // disable\n```\n\n### `shouldComponentUpdate`\n\nBy default, `orwell` uses a `shouldComponentUpdate()` that is equivalent to React's [`PureRenderMixin`](https://facebook.github.io/react/docs/pure-render-mixin.html), but compares [Probe](https://github.com/Dashed/probe) different by doing something like:\n\n```js\n!(currentProbe.deref() === nextProbe.deref())\n```\n\nThe props passed to `shouldComponentUpdate(nextProps, nextState)` is equivalent to `Object.assign({}, props, assignNewProps(props, context))`.\n\n## Inspiration\n\n`orwell` has been inspired by `connectToStores` code written by [@gaearon](https://github.com/gaearon) in his article promoting usage of Higher-order components: https://medium.com/@dan_abramov/mixins-are-dead-long-live-higher-order-components-94a0d2f9e750\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdashed%2Forwell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdashed%2Forwell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdashed%2Forwell/lists"}