{"id":19131268,"url":"https://github.com/kristoferjoseph/redeux","last_synced_at":"2025-05-06T16:04:51.396Z","repository":{"id":9880005,"uuid":"63641844","full_name":"kristoferjoseph/redeux","owner":"kristoferjoseph","description":"Minimal unidirectional data flow utility library","archived":false,"fork":false,"pushed_at":"2022-12-07T17:46:37.000Z","size":483,"stargazers_count":57,"open_issues_count":10,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-24T03:39:19.322Z","etag":null,"topics":["data","flux","reducer","store","unidirectional","utility"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kristoferjoseph.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-07-18T22:36:19.000Z","updated_at":"2024-07-08T18:56:28.000Z","dependencies_parsed_at":"2023-01-13T15:37:02.089Z","dependency_job_id":null,"html_url":"https://github.com/kristoferjoseph/redeux","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristoferjoseph%2Fredeux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristoferjoseph%2Fredeux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristoferjoseph%2Fredeux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristoferjoseph%2Fredeux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kristoferjoseph","download_url":"https://codeload.github.com/kristoferjoseph/redeux/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252423647,"owners_count":21745625,"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":["data","flux","reducer","store","unidirectional","utility"],"created_at":"2024-11-09T06:14:41.078Z","updated_at":"2025-05-06T16:04:51.343Z","avatar_url":"https://github.com/kristoferjoseph.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# redeux\nMinimal unidirectional data flow utility library.\n\n- Written in plain 'ol JavaScript so **no transpile needed**⚡️\n- Tiny💥\n    - [~1k](https://github.com/kristoferjoseph/redeux/blob/master/index.js)\n- Simple api:\n    - **store**\n      - returns the current state\n        - **store.register**\n          - register any number of reducers\n        - **store.subscribe**\n          - subscribe a function to receive state updates\n        - **store.unsubscribe**\n          - unsubscribe a function from state updates\n        - **store.dispatch**\n          - dispatch an action\n\n## Install\n\n##### node\n\n`npm i redeux --save`\n\n##### script\n\n[`\u003cscript src=\"redeux.umd.js\"\u003e\u003c/script\u003e`](https://github.com/kristoferjoseph/redeux/blob/master/example.html)\n\n##### es module\n\n`import Redeux from 'https://unpkg.com/redeux?module'`\n\n## Usage\n\n#### reducer\n\nthis is what a reducer looks like\n\n```js\n// Default state\nvar initialState = []\n\n// By defualt the reducer function's name property\n//  will be used as the key for the data atom\n//  NOTE: You can also add the `key` property to your reducer function\n//  i.e.: `todos.key = todos` useful for when you want to use uglify and mangle is changing function names.\nmodule.exports = function todos (state, action) {\n  // Guard against undefined action\n  action = action || {}\n\n  // You can use whatever keys you like in your actions,\n  //  but i find a type and data works best for me\n  var type = action.type\n  var data = action.data\n\n  // Guard against undefined state\n  //  by initializing with initial state\n  state = state || initialState\n\n  switch (type) {\n    case 'ADD':\n      return add(state, data)\n      break;\n    default:\n      return state;\n  }\n}\n\n// The add function will get passed the current state and the action data\nfunction add (state, data) {\n  // Make a copy of the array\n  var newState = state.concat()\n\n  // Change the copy\n  newState.push(data)\n\n  // Return the changed copy\n  return newState\n}\n\nconsole.log(store()) // { todos: [] }\n```\n\n#### Registering a reducer\n\n```js\nvar todos = require('./reducers/todos')\nvar initialState = {todos: [1,2,3]}\nvar store = require('redeux')(initialState)\n// You can pass as many reducers as you want to register\nstore.register(todos)\n```\n\n#### Dispatching an action\n\n```js\nvar store = require('redeux')()\nstore.dispatch({type: 'ADD', data: '1'})\n```\n\n#### Subscribing a listener\n\n```js\nvar initialState = {todos: [0]}\nvar store = require('redeux')(initialState)\nvar todos = require('./reducers/todos')\nstore.register(todos)\nstore.subscribe(update)\nstore.dispatch({type:'ADD', data: 1})\nstore.unsubscribe(update)\n\nfunction update(state, action) {\n  console.log(state) // {todos[0, 1]}\n}\n```\n\n_btw redeux works really well with [hash-switch](https://github.com/kristoferjoseph/hash-switch)_\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkristoferjoseph%2Fredeux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkristoferjoseph%2Fredeux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkristoferjoseph%2Fredeux/lists"}