{"id":20022231,"url":"https://github.com/lucifier129/relite","last_synced_at":"2025-05-05T01:31:24.108Z","repository":{"id":54377544,"uuid":"66445906","full_name":"Lucifier129/relite","owner":"Lucifier129","description":"a redux-like library for managing state with simpler api","archived":false,"fork":false,"pushed_at":"2020-08-26T11:33:31.000Z","size":233,"stargazers_count":58,"open_issues_count":1,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-08T14:52:28.446Z","etag":null,"topics":["flux","immutable","pure-function","redux-like","store"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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":"2016-08-24T08:28:27.000Z","updated_at":"2025-03-20T07:44:57.000Z","dependencies_parsed_at":"2022-08-13T13:50:37.196Z","dependency_job_id":null,"html_url":"https://github.com/Lucifier129/relite","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%2Frelite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lucifier129%2Frelite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lucifier129%2Frelite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lucifier129%2Frelite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lucifier129","download_url":"https://codeload.github.com/Lucifier129/relite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252423132,"owners_count":21745547,"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":["flux","immutable","pure-function","redux-like","store"],"created_at":"2024-11-13T08:39:37.441Z","updated_at":"2025-05-05T01:31:19.098Z","avatar_url":"https://github.com/Lucifier129.png","language":"TypeScript","readme":"# relite\na redux-like library for managing state with simpler api (1kb)\n\n# Why\nredux is awesome, but is not enough simple for small and middle application. \n\nWith `relite`, we don't need to `combine | apply | bind` anything, just write pure function and call actions, it done.\n\n# What's new(3.0.0)\n\n+ Supoort `Typescript`.\n\n+ Delete the support of return type `Promise | Function` of `Action`.\n\n# Installtion\n\n```shell\nnpm install --save relite\n```\n\n# How to use\n\n## write pure function\n\nthe action of `relite` looks like a reducer of redux, but more simple and powerful.\n\n```javascript\n/**\n* an action consist of action-type, action-payload, action-handler and action-result\n* at this example\n* action-type is EXEC_BY\n* action-handler is the function accepts two arguments: state and action-payload\n* action-result is the result of function\n*/\nexport let EXEC_BY = (state, input) =\u003e {\n\tlet value = parseFloat(input, 10)\n\treturn isNaN(value) ? state : {\n\t\t...state,\n\t\tcount: state.count + value\n\t}\n}\n```\n\n## create store by actions and initialState\n\n```javascript\nimport { createStore } from 'relite'\nimport * as actions from './actions'\n\nlet initialState = {\n\tcount: 0,\n}\nlet store = createStore(actions, intialState)\n\n/*\n* relite will bind state for every actions you gave to `createStore`\n* so all the functions in store.actions can only accept one argument, action-payload\n* no need to bindActionCreators\n* each actions return currentState or promise with currentState\n*/\nlet { INCREMENT, EXEC_BY } = store.actions\nINCREMENT() // -\u003e { count: 1 }\nEXEC_ASYNC(9) // -\u003e Promise[[{ count: 10 }]]\n\n/**\n* subscribe store by store.subscribe\n* when the state was changed/updateed, relite would trigger the listeners\n* if action-handler return the same state, listeners would not be triggered\n*/\nlet unsubscribe = store.subscribe((data) =\u003e {\n\tlet {\n\t\tactionType, // action-type\n\t\tactionPayload, // action-payload\n\t\tstart, // start date\n\t\tend, // end date\n\t\tpreviousState, // prev-state\n\t\tcurrentState // cur-state\n\t} = data\n})\n\nlet newState = {\n\tcount: 0,\n}\nlet simulateData = {\n\tactionType: 'REPLACE_STATE',\n\tactionPayload: null,\n\tstart: new Date(),\n\tend: new Date,\n\tpreviousState: store.getState(), // get current state\n\tcurrentState: newState,\n}\nlet keepSilent = false // if true, it will not trigger listeners\n\n// replace state by store.replaceState\nstore.replaceState(newState, simulateData, false)\n\n// trigger listener by store.publish\nstore.publish(simulateData)\n\nstore.dispatch('EXEC_ASYNC', 10) // dispatch the action manually\n\n```\n\n## use build-in logger\n\n```javascript\nimport { createStore } from 'relite'\nimport * as actions from './actions'\n\nlet initialState = {\n\tcount: 0,\n}\nlet store = createStore(actions, intialState)\n\nstore.subscribe(render)\n\nrender()\n\nfunction render() {\n\tReactDOM.render(\n\t\t\u003cApp {...store.getState()} {...store.actions} /\u003e,\n\t\tdocument.getElementById('container')\n\t)\n}\n```\n\n# End\nIssue and pull request is welcome!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucifier129%2Frelite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucifier129%2Frelite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucifier129%2Frelite/lists"}