{"id":27068001,"url":"https://github.com/oreshinya/actionizer","last_synced_at":"2025-04-05T20:17:24.592Z","repository":{"id":57140732,"uuid":"60458622","full_name":"oreshinya/actionizer","owner":"oreshinya","description":"Simple pub/sub for data flow like Redux.","archived":false,"fork":false,"pushed_at":"2017-01-28T06:51:55.000Z","size":41,"stargazers_count":22,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-04T17:44:01.853Z","etag":null,"topics":["data-flow","pubsub","redux","redux-saga"],"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/oreshinya.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-06-05T12:20:26.000Z","updated_at":"2025-02-20T17:14:01.000Z","dependencies_parsed_at":"2022-09-01T23:50:55.719Z","dependency_job_id":null,"html_url":"https://github.com/oreshinya/actionizer","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oreshinya%2Factionizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oreshinya%2Factionizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oreshinya%2Factionizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oreshinya%2Factionizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oreshinya","download_url":"https://codeload.github.com/oreshinya/actionizer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247272801,"owners_count":20911811,"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-flow","pubsub","redux","redux-saga"],"created_at":"2025-04-05T20:17:24.013Z","updated_at":"2025-04-05T20:17:24.582Z","avatar_url":"https://github.com/oreshinya.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Actionizer\n[![npm version](https://badge.fury.io/js/actionizer.svg)](https://badge.fury.io/js/actionizer)\n[![Build Status](https://travis-ci.org/oreshinya/actionizer.svg?branch=master)](https://travis-ci.org/oreshinya/actionizer)\n\nThis is just pub/sub for data flow like Redux.\n\n## Overview\n\n```\n\n  Command -\u003e (Web API)\n    ^  _________|\n    |  v\n   Action -\u003e Command -\u003e (Reducer) -\u003e Store -\u003e View\n     ^                                         |\n     |_________________________________________|\n\n```\n\n## Dependencies\n\n`babel-polyfill` for ES2015 generator.\n\n## Installation\n\n```\n$ npm i --save actionizer\n```\n\n## Usage\n\n```javascript\nimport 'babel-polyfill';\nimport axios from 'axios';\nimport { fromJS } from 'immutable';\nimport { createStore } from 'actionizer';\nimport { select, call, reduce, fork, cancel, delegate } from 'actionizer/commands';\nimport debounce from 'lodash.debounce';\n\nconst initialState = fromJS({\n  counter: 0,\n  items: {\n    1: {id: 1, name: 'hoge'},\n    2: {id: 2, name: 'fuga'}\n  }\n});\n\n// Customize notifier.\nconst notify = debounce((emit) =\u003e { emit(); });\n\n// Create \"Store\", it treats states for the app.\nconst store = createStore(initialState, notify);\n\n// Define \"Reducer\"\nconst setCount = (state, num) =\u003e state.set('counter', num);\n\n// Define \"Action Creator\".\nconst count = function*(num) {\n  // Get current state.\n  const state = yield select();\n\n  // Update state by \"Reducer\"\n  yield reduce(setCount, num);\n}\n\n// API request.\nconst getItems = (id, field) =\u003e {\n  return axios.get('/items', {id, field});\n};\n\n// Define asynchronous \"Action Creator\".\nconst fetchItems = function*(id, field) {\n  try {\n    // \"call\" receives a function and arguments that returns a promise.\n    const result = yield call(getItems, id, field);\n\n    // Do something...\n  } catch(e) {\n    // Do something...\n  }\n}\n\nconst sleep = (ms) =\u003e {\n  return new Promise((resolve) =\u003e {\n    setTimeout(() =\u003e { resolve(); }, ms);\n  });\n};\n\n// Define debounced \"Action Creator\".\nconst debouncedFetchItems = function*(id) {\n  yield call(sleep, 1000);\n  // Delegate other action creator\n  yield delegate(fetchItems, id);\n}\nlet actionId;\nconst searchItemsById = function*(id) {\n  yield cancel(actionId);\n  actionId = yield fork(debouncedFetchItems, id);\n}\n\n// Subscribe store's change.\nconst unsubscribe = store.subscribe((state) =\u003e {\n  console.log(`listener: ${state.get('counter')}`);\n});\n\n// Dispatch \"Action\".\nstore.dispatch(count(100));\n\n// =\u003e listener: 100\n\n// Unsubscribe store's change.\nunsubscribe();\n```\n\n## API\n### Top level API\n#### `createStore(initialState, notify)`\nCreate a store.\n\n#### `compose(...funcs)`\nComposes functions from right to left.\n\n### Store API\n#### `subscribe(listener)`\nRegister a listener of store's changes.\nAnd it returns unsubscriber.\n\n#### `dispatch(action, callback)`\nTrigger an action.\nIn Actionizer, \"Action\" is a generator like:\n\n```javascript\n// This is \"Action Creator\"\nconst count = function*(num) {\n  yield reduce(setCount, num);\n}\n\n// This is \"Action\"\nconst action = count(1);\n```\n\n#### `getState()`\nGet store's state.\n\n### Command API\n\"Command\" return a payload used in \"Action Creator\".\n\n#### `select(selector = (state) =\u003e state)`\n`select` calls `selector` with current state, and return `selector` result.\n\n#### `reduce(reducer, ...args)`\n`reduce` updates state by result of `reducer`.\n\n#### `call(fn, ...args)`\n`call` calls `fn` with `args`.\n`fn` should return `Promise`.\n`call` returns resolved value.\n\n#### `fork(actionCreator, ...args)`\n`fork` calls an action without blocking and returns action id.\nAction id is unique.\n\n#### `delegate(actionCreator, ...args)`\n`delegate` delegates process to other action by calling action creator.\n\n#### `cancel(actionId)`\n`cancel` cancels action by action id.\n\n## Related projects\n- [react-actionizer](https://github.com/oreshinya/react-actionizer)\n\n## LICENSE\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foreshinya%2Factionizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foreshinya%2Factionizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foreshinya%2Factionizer/lists"}