{"id":32634160,"url":"https://github.com/ericfong/create-mutable-context","last_synced_at":"2026-04-18T03:32:50.014Z","repository":{"id":144924200,"uuid":"125615024","full_name":"ericfong/create-mutable-context","owner":"ericfong","description":"wrap new React.createContext() to provide context with setState function for Consumer","archived":false,"fork":false,"pushed_at":"2018-03-24T05:17:30.000Z","size":107,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-23T14:02:41.803Z","etag":null,"topics":["context","mutable","react"],"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/ericfong.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-17T09:36:37.000Z","updated_at":"2025-09-09T18:53:40.000Z","dependencies_parsed_at":"2023-04-25T04:02:32.950Z","dependency_job_id":null,"html_url":"https://github.com/ericfong/create-mutable-context","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/ericfong/create-mutable-context","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericfong%2Fcreate-mutable-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericfong%2Fcreate-mutable-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericfong%2Fcreate-mutable-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericfong%2Fcreate-mutable-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericfong","download_url":"https://codeload.github.com/ericfong/create-mutable-context/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericfong%2Fcreate-mutable-context/sbom","scorecard":{"id":380273,"data":{"date":"2025-08-11","repo":{"name":"github.com/ericfong/create-mutable-context","commit":"25f7dd322b7e598f710396880175961cae755eee"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.6,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-18T15:16:29.289Z","repository_id":144924200,"created_at":"2025-08-18T15:16:29.290Z","updated_at":"2025-08-18T15:16:29.290Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31955719,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["context","mutable","react"],"created_at":"2025-10-30T23:58:50.436Z","updated_at":"2026-04-18T03:32:50.008Z","avatar_url":"https://github.com/ericfong.png","language":"JavaScript","readme":"really minimal wrap on new React.createContext() to provide context with a set function for Consumer\n\n\n\n# NOTE\n\nAccording to [0002-new-version-of-context](https://github.com/reactjs/rfcs/blob/master/text/0002-new-version-of-context.md#relies-on-strict-comparison-of-context-values), mutation is discouraged. But in some situations, Consumer really need a way to update the Provider. So, I come up with this module.\n\n\n\n# Usage\n\n```js\nimport createMutableContext from 'create-mutable-context'\n\nconst { Provider, Consumer } = createMutableContext()\n\n\u003cProvider defaultValue={1}\u003e\n  \u003cConsumer\u003e\n    {ctx =\u003e {\n      // ctx contain value and a set function\n      return (\n        \u003cbutton onClick={() =\u003e ctx.set(ctx.value + 1)}\u003e\n          {ctx.value}\n        \u003c/button\u003e\n      )\n    }}\n  \u003c/Consumer\u003e\n\u003c/Provider\u003e\n```\n\n\n\n## ctx.set()\n\n```js\nset(updater[, callback])\n```\n\nset function interface is similar to react component's setState(), which accept updater as `object` or `function`.\n\nupdater as function with the signature:\n```js\n(prevValue, providerProps) =\u003e newValue\n```\n\n**set will just replace the value. It will NOT merge newValue to prevValue.**\n\n\n\n## keep value in your own state by Provider.onChange\n\nyou can also keep value in your own state (like Input)\n\n```js\nimport createMutableContext from 'create-mutable-context'\n\nconst { Provider, Consumer } = createMutableContext()\n\nclass App extends React.Component {\n  state = { valueA: 1 }\n  render() {\n    return (\n      \u003cProvider\n        value={this.state.valueA}\n        onChange={valueA =\u003e this.setState({ valueA })}\n      \u003e\n      ...\n      \u003c/Provider\u003e\n    )\n  }\n}\n```\n\n\n## access via ctx.foo instead ctx.value.foo\n\nCan use `createStateMutext` to mutate whole provider state instead of a value field only.\n\n```js\nimport { createStateMutext } from 'create-mutable-context'\n\nconst C = createStateMutext({ foo: 1 })\n\nconst App = () =\u003e (\n  \u003cC.Provider\u003e\n    \u003cC.Consumer\u003e\n      {ctx =\u003e (\n        \u003cbutton\n          onClick={() =\u003e ctx.set({ foo: ctx.foo + 1 })}\n        \u003e\n          {ctx.foo}\n        \u003c/button\u003e\n      )}\n    \u003c/C.Consumer\u003e\n  \u003c/C.Provider\u003e\n)\n```\n\n\n## createObservableMutext\n\nConsumers can observe part of changes easily by names. Names are auto calculate to bitmask\n\n```js\nimport { createObservableMutext } from 'create-mutable-context'\n\nconst C = createObservableMutext({ foo: 0, bar: 0 }, { foo: {}, bar: {} })\n\nconst App = () =\u003e (\n  \u003cC.Provider\u003e\n    \u003cC.Consumer\n      // observe to foo and only render if foo is changed\n      observe=\"foo\"\n    \u003e\n      {ctx =\u003e `Foo: ${ctx.foo}`}\n    \u003c/C.Consumer\u003e\n    \u003cC.Consumer\n      // observe to bar and only render if bar is changed\n      observe=\"bar\"\n    \u003e\n      {ctx =\u003e `Bar: ${ctx.bar}`}\n    \u003c/C.Consumer\u003e\n    \u003cC.Consumer\n      // observe to bar OR foo and render if bar OR foo are changed\n      observe=\"bar,foo\"\n    \u003e\n      {ctx =\u003e `BarOrFoo: ${ctx.bar} ${ctx.foo}`}\n    \u003c/C.Consumer\u003e\n  \u003c/C.Provider\u003e\n)\n```\n\n\n## use option to add functions to ctx\n\ncreateMutableContext signature:\n```js\nimport createMutableContext from 'create-mutable-context'\n\nconst options = {\n  // init at the end of provider constructor\n  providerConstruct: (provider) =\u003e {},\n\n  // init at the end of consumer constructor\n  consumerConstruct: (consumer) =\u003e {},\n\n  // prepare ctx to pass to consumer children function\n  consumerCtx: (ctx, consumer) =\u003e ctx,\n}\ncreateMutableContext(defaultValue, calculateChangedBits, option)\n\nconst C = createMutableContext(defaultValue, null, {\n  providerConstruct(provider) {\n    Object.assign(provider.state, {\n      inc1() {\n        this.set(prevState =\u003e { value: prevState.value + 1 })\n      }\n    })\n  },  \n})\n\nconst App = () =\u003e (\n  \u003cC.Provider\u003e\n    \u003cC.Consumer\u003e\n      {ctx =\u003e (\n        \u003cbutton\n          // can call inc1\n          onClick={ctx.inc1}\n        \u003e\n          {ctx.value}\n        \u003c/button\u003e\n      )}\n    \u003c/C.Consumer\u003e\n  \u003c/C.Provider\u003e\n)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericfong%2Fcreate-mutable-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericfong%2Fcreate-mutable-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericfong%2Fcreate-mutable-context/lists"}