{"id":19189652,"url":"https://github.com/ovrmrw/ngrx-store-simplr","last_synced_at":"2025-05-08T03:15:57.046Z","repository":{"id":65458329,"uuid":"88948266","full_name":"ovrmrw/ngrx-store-simplr","owner":"ovrmrw","description":"A wrapper library for @ngrx/store to use Redux concept in an easy way.","archived":false,"fork":false,"pushed_at":"2017-05-09T13:58:07.000Z","size":90,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-08T03:15:51.398Z","etag":null,"topics":["angular","ngrx-store","ngrx-store-simplr","rxjs","typescript"],"latest_commit_sha":null,"homepage":"","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/ovrmrw.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":"2017-04-21T06:15:23.000Z","updated_at":"2021-09-12T18:10:15.000Z","dependencies_parsed_at":"2023-01-24T13:15:28.641Z","dependency_job_id":null,"html_url":"https://github.com/ovrmrw/ngrx-store-simplr","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/ovrmrw%2Fngrx-store-simplr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovrmrw%2Fngrx-store-simplr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovrmrw%2Fngrx-store-simplr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovrmrw%2Fngrx-store-simplr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ovrmrw","download_url":"https://codeload.github.com/ovrmrw/ngrx-store-simplr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252990004,"owners_count":21836668,"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":["angular","ngrx-store","ngrx-store-simplr","rxjs","typescript"],"created_at":"2024-11-09T11:30:39.856Z","updated_at":"2025-05-08T03:15:56.994Z","avatar_url":"https://github.com/ovrmrw.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simplr\nA wrapper library for @ngrx/store to use Redux concept in an easy way.\n\n---\n\nMaybe your desires:\n\n- like to use Redux.\n- but writing many actions and reducers is painful.\n- very painful.\n- to handle async actions is so painful.\n- finding an easy way to use Redux concept.\n- want to use Angular and RxJS.\n\nHere Simplr comes into play.\n\n## Install\n\n```\n$ npm install --save @ngrx/core @ngrx/store ngrx-store-simplr\n```\n\nYou also need to install Angular and RxJS.\n\n---\n\n## Examples\n\n- [simplr-counter](https://github.com/ovrmrw/simplr-counter)\n- [simplr-timestamp](https://github.com/ovrmrw/simplr-timestamp)\n\n---\n\n## Usage\n\nDeclare the app state interfaces.\n\n```ts\n// app/store/models/index.ts\n\nexport interface AppState {\n  counter: number;\n}\n```\n\nCreate `reducer` and `initialState` to import into `app.module.ts`.\n\n```ts\n// app/store/reducer.ts\n\nimport { combineReducers } from '@ngrx/store';\nimport { Wrapper } from 'ngrx-store-simplr';\nimport { AppState } from './models';\n\nconst wrapper = new Wrapper\u003cAppState\u003e();\n\nconst wrappedReducers = wrapper.mergeReducersIntoWrappedReducers({\n  counter: null // if you have a reducer for this key, set it here instead of null.\n});\n\nconst rootReducer = combineReducers(wrappedReducers);\n\nexport function reducer(state, action) { // workaround for AoT compile\n  return rootReducer(state, action);\n}\n\nexport const initialState: AppState = {\n  counter: 0\n};\n```\n\nEdit `app.module.ts` in order to use Simplr.\n\n```ts\n// app/app.module.ts\n\nimport { StoreModule } from '@ngrx/store';\nimport { SimplrModule } from 'ngrx-store-simplr';\nimport { reducer, initialState } from './store/reducer';\n\n@NgModule({\n  imports: [ \n    ...,\n    StoreModule.provideStore(reducer, initialState), // \u003c== Add\n    SimplrModule.forRoot(), // \u003c== Add\n  ],\n})\nexport class AppModule { }\n```\n\nCreate a service to dispatch to the store.\n\n```ts\n// app/services/counter.ts\n\nimport { Simplr } from 'ngrx-store-simplr';\nimport { AppState } from '../store/models';\nimport { initialState } from '../store/reducer';\n\n@Injectable()\nexport class CounterService {\n  constructor(\n    private simplr: Simplr\u003cAppState\u003e,\n  ) { }\n\n  increment() {\n    this.simplr.dispatch('counter', (state) =\u003e state + 1);\n  }\n\n  reset() {\n    this.simplr.dispatch('counter', initialState.counter);\n  }\n}\n```\n\nCreate a component to call service functions.\n\n```ts\n// app/containers/counter.ts\n\nimport { State } from '@ngrx/store';\nimport { AppState } from '../store/models';\nimport { CounterService } from '../services/counter';\n\n@Component({\n  selector: 'app-counter-container',\n  template: `\n    \u003cbutton (click)=\"increment()\"\u003eincrement\u003c/button\u003e\n    \u003cbutton (click)=\"reset()\"\u003ereset\u003c/button\u003e\n    \u003cpre\u003e{{ state$ | async | json }}\u003c/pre\u003e\n  `\n})\nexport class CounterContainerComponent {\n  constructor(\n    public state$: State\u003cAppState\u003e,\n    private service: CounterService,\n  ) { }\n\n  increment() {\n    this.service.increment();\n  }\n\n  reset() {\n    this.service.reset();\n  }\n}\n```\n\nDone!  \nDid you notice that you wrote no actions and no reducers?\n\n---\n\n## Demos\n\n- [simplr-counter on GitHub Pages](https://ovrmrw.github.io/simplr-counter/)\n- [simplr-timestamp on GitHub Pages](https://ovrmrw.github.io/simplr-timestamp/)\n\n---\n\n## Details\n\n### dispatch\n\n#### `dispatch` function allows below sync and async writings.\n\n```ts\nthis.simplr.dispatch('counter', (state) =\u003e state + 1 ) // callback\n// or\nthis.simplr.dispatch('counter', 1) // value\n// or \nthis.simplr.dispatch('counter', Promise.resolve((state) =\u003e state + 1 )) // callback in Promise\n// or\nthis.simplr.dispatch('counter', Promise.resolve(1)) // value in Promise\n// or\nthis.simplr.dispatch('counter', Observable.of((state) =\u003e state + 1 )) // callback in Observable\n// or\nthis.simplr.dispatch('counter', Observable.of(1)) // value in Observable\n```\n\n#### `dispatch` function returns Observable result especially for testing.\n\n```ts\ninterface Result\u003cT, K extends keyof T\u003e {\n  action: Action,\n  state: T,\n  partial: T[K],\n}\n```\n\n```ts\n// getting dispatched Action\nconst action: Observable\u003cAction\u003e = \n  this.simplr\n    .dispatch('counter', (state) =\u003e state + 1 )\n    .map(result =\u003e result.action) // action ==\u003e { type: 'counter @UPDATE@', payload: 1 }\n\n// getting updated current whole state\nconst state: Observable\u003cAppState\u003e =\n  this.simplr\n    .dispatch('counter', (state) =\u003e state + 1 )\n    .map(result =\u003e result.state) // state ==\u003e { counter: 1 }\n\n// getting udpated current state under the key\nconst partial: Observable\u003cnumber\u003e =\n  this.simplr\n    .dispatch('counter', (state) =\u003e state + 1 )\n    .map(result =\u003e result.partial) // partial ==\u003e 1\n```\n\n#### `dispatch` function allows to set some options.\n\n```ts\n// description option\nconst action: Observable\u003cAction\u003e = \n  this.simplr\n    .dispatch('counter', (state) =\u003e state + 1, { desc: 'foobar' } )\n    .map(result =\u003e result.action) // action ==\u003e { type: 'counter @UPDATE@', payload: 1, desc: 'foobar' }\n\n// timeout option (default: 1000 * 15)\nconst action: Observable\u003cAction\u003e = \n  this.simplr\n    .dispatch('counter', Observable.of((state) =\u003e state + 1).delay(100), { timeout: 90 } )\n    .map(result =\u003e result.action) // action ==\u003e { type: 'counter @FAILED@' }\n\n// retry option (default: 3)\nthis.simplr.dispatch('counter', /* will try this HTTP request 10 times */, { retry: 10 } )\n\n// logging option ... if set be true, the result will be shown on browser console.\nthis.simplr.dispatch('counter', (state) =\u003e state + 1, { logging: true } )\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fovrmrw%2Fngrx-store-simplr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fovrmrw%2Fngrx-store-simplr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fovrmrw%2Fngrx-store-simplr/lists"}