{"id":20022247,"url":"https://github.com/lucifier129/youmightnotneedflux","last_synced_at":"2025-05-05T01:31:26.754Z","repository":{"id":77718322,"uuid":"45965254","full_name":"Lucifier129/youmightnotneedflux","owner":"Lucifier129","description":"you might not need flux","archived":false,"fork":false,"pushed_at":"2015-11-11T10:19:45.000Z","size":0,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T14:52:31.747Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Lucifier129.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-11-11T07:01:25.000Z","updated_at":"2022-03-07T15:31:31.000Z","dependencies_parsed_at":"2023-03-09T04:00:28.654Z","dependency_job_id":null,"html_url":"https://github.com/Lucifier129/youmightnotneedflux","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/Lucifier129%2Fyoumightnotneedflux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lucifier129%2Fyoumightnotneedflux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lucifier129%2Fyoumightnotneedflux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lucifier129%2Fyoumightnotneedflux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lucifier129","download_url":"https://codeload.github.com/Lucifier129/youmightnotneedflux/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252423156,"owners_count":21745551,"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-13T08:39:42.166Z","updated_at":"2025-05-05T01:31:23.612Z","avatar_url":"https://github.com/Lucifier129.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# youmightnotneedflux\nyou might not need flux/redux\n\n## It is hard to choice the flux library\n\nThere are too many flux library.\n\n## flux in 30 lines\n\nThe flux store can be a class.\n\nThe action function is a store method which has bound `this`, so that you can pass action everywhere and call it without error.\n\n```javascript\nclass Store {\n\tconstructor(props = {}, initialState = {}) {\n\t\tthis.state = initialState\n\t\tthis.actions = {}\n\t\tthis.listeners = []\n\t\tObject.assign(this, props)\n\t\tfor (let key in this) {\n\t\t\tif (typeof this[key] === 'function') {\n\t\t\t\tthis.actions[key] = (...args) =\u003e {\n\t\t\t\t\tthis[key](...args)\n\t\t\t\t\tthis.listeners.forEach(listener =\u003e listener(key, ...args))\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tgetState() {\n\t\treturn this.state\n\t}\n\treplaceState(nextState) {\n\t\tthis.state = nextState\n\t}\n\tsubscribe(listener) {\n\t\tthis.listeners.push(listener)\n\t\treturn () =\u003e {\n\t\t\tlet index = this.listeners.indexOf(listener)\n\t\t\tif (index \u003e= 0) {\n\t\t\t\tthis.listeners.splice(index, 1)\n\t\t\t}\n\t\t}\n\t}\n}\n```\n\n## how to write custom action?\n\njust pass props param to `new Store`.\n\n```javascript\nvar props = {\n\tADD_ITEM: function(item) {\n\t\tthis.state.list.push(item)\n\t},\n\tDELETE_ITEM: function(item) {\n\t\tlet index = this.state.list.indexOf(item)\n\t\tif (index !== -1) this.state.list.splace(index, 1)\t\n\t}\n}\nvar store = new Store(props, { list: [] })\nvar { ADD_ITEM, DELETE_ITEM } = store.actions\nvar item = { a: 1}\nADD_ITEM(item)\nstore.getState() // { list: [{ a: 1 }]}\nDELETE_ITEM(item)\nstore.getState() // { list: []}\n```\n\n## how to write middleware ?\n\njust inherit Store like below:\n\n```javascript\nlet logger = Store =\u003e {\n\tlet log = (actionType, actionHandler) =\u003e (...args) =\u003e {\n\t\tconsole.log(`action ${ actionType } invoke by [${ args }]`)\n\t\tconsole.time(actionType)\n\t\tactionHandler(...args)\n\t\tconsole.timeEnd(actionType)\n\t}\n\treturn class StoreWithLogger extends Store {\n\t\tconstructor(props, initialState) {\n\t\t\tsuper(props, initialState)\n\t\t\tthis.actions = this.actions.map(log)\n\t\t}\n\t}\n}\n```\n\n## TODO...","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucifier129%2Fyoumightnotneedflux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucifier129%2Fyoumightnotneedflux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucifier129%2Fyoumightnotneedflux/lists"}