{"id":13492729,"url":"https://github.com/investtools/extensible-duck","last_synced_at":"2026-05-13T02:18:12.529Z","repository":{"id":47422534,"uuid":"86253659","full_name":"investtools/extensible-duck","owner":"investtools","description":"Modular and Extensible Redux Reducer Bundles (ducks-modular-redux)","archived":false,"fork":false,"pushed_at":"2022-12-03T03:18:11.000Z","size":731,"stargazers_count":148,"open_issues_count":14,"forks_count":12,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-10-03T08:41:31.038Z","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/investtools.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-03-26T18:07:07.000Z","updated_at":"2025-01-04T03:50:28.000Z","dependencies_parsed_at":"2023-01-23T04:15:36.902Z","dependency_job_id":null,"html_url":"https://github.com/investtools/extensible-duck","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/investtools/extensible-duck","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/investtools%2Fextensible-duck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/investtools%2Fextensible-duck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/investtools%2Fextensible-duck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/investtools%2Fextensible-duck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/investtools","download_url":"https://codeload.github.com/investtools/extensible-duck/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/investtools%2Fextensible-duck/sbom","scorecard":{"id":492261,"data":{"date":"2025-08-11","repo":{"name":"github.com/investtools/extensible-duck","commit":"9a103ff83d7e98f1ea8b2b87114d7c87e5066333"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.1,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":3,"reason":"Found 6/20 approved changesets -- score normalized to 3","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 16 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"82 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-6chw-6frg-f759","Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx","Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9","Warn: Project is vulnerable to: GHSA-vh7m-p724-62c2","Warn: Project is vulnerable to: GHSA-r9p9-mrjm-926w","Warn: Project is vulnerable to: GHSA-434g-2637-qmqr","Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m","Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw","Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p","Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747","Warn: Project is vulnerable to: GHSA-vjh7-7g9h-fjfh","Warn: Project is vulnerable to: GHSA-4gmj-3p3h-gm8h","Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3","Warn: Project is vulnerable to: MAL-2023-462","Warn: Project is vulnerable to: GHSA-qh2h-chj9-jffq","Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6","Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9","Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f","Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p","Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv","Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8","Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65","Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh","Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44","Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37","Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546","Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-282f-qqgm-c34q","Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp","Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq","Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488","Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g","Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695","Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm","Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574","Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-hxm2-r34f-qmc5","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-fhjf-83wg-r2j9","Warn: Project is vulnerable to: GHSA-w9mr-4mfr-499f","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-h7cp-r72f-jxh6","Warn: Project is vulnerable to: GHSA-v62p-rq8g-8h59","Warn: Project is vulnerable to: GHSA-gqgv-6jq5-jjj9","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp","Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr","Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6","Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj","Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9","Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw","Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc","Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh","Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-cf4h-3jhx-xvhq","Warn: Project is vulnerable to: GHSA-g78m-2chm-r7qv","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh","Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T19:29:15.292Z","repository_id":47422534,"created_at":"2025-08-19T19:29:15.292Z","updated_at":"2025-08-19T19:29:15.292Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32964557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-12T23:30:32.555Z","status":"online","status_checked_at":"2026-05-13T02:00:07.132Z","response_time":115,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-07-31T19:01:08.672Z","updated_at":"2026-05-13T02:18:12.510Z","avatar_url":"https://github.com/investtools.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# extensible-duck\n\nextensible-duck is an implementation of the [Ducks proposal](https://github.com/erikras/ducks-modular-redux). With this library you can create reusable and extensible ducks.\n\n[![Travis build status](http://img.shields.io/travis/investtools/extensible-duck.svg?style=flat)](https://travis-ci.org/investtools/extensible-duck)\n[![Code Climate](https://codeclimate.com/github/investtools/extensible-duck/badges/gpa.svg)](https://codeclimate.com/github/investtools/extensible-duck)\n[![Test Coverage](https://codeclimate.com/github/investtools/extensible-duck/badges/coverage.svg)](https://codeclimate.com/github/investtools/extensible-duck)\n[![Dependency Status](https://david-dm.org/investtools/extensible-duck.svg)](https://david-dm.org/investtools/extensible-duck)\n[![devDependency Status](https://david-dm.org/investtools/extensible-duck/dev-status.svg)](https://david-dm.org/investtools/extensible-duck#info=devDependencies)\n![](http://img.badgesize.io/investtools/extensible-duck/master/dist/extensible-duck.min.js?compression=gzip)\n\n\u003c!-- MarkdownTOC autolink=\"true\" bracket=\"round\" autoanchor=\"false\" markdown_preview=\"github\" --\u003e\n\n- [Basic Usage](#basic-usage)\n  - [Constructor Arguments](#constructor-arguments)\n  - [Duck Accessors](#duck-accessors)\n  - [Defining the Reducer](#defining-the-reducer)\n  - [Defining the Creators](#defining-the-creators)\n  - [Defining the sagas](#defining-the-sagas)\n  - [Defining the Initial State](#defining-the-initial-state)\n  - [Defining the Selectors](#defining-the-selectors)\n  - [Defining the Types](#defining-the-types)\n  - [Defining the Constants](#defining-the-constants)\n- [Creating Reusable Ducks](#creating-reusable-ducks)\n- [Extending Ducks](#extending-ducks)\n- [Creating Reusable Duck Extensions](#creating-reusable-duck-extensions)\n- [Creating Ducks with selectors](#creating-ducks-with-selectors)\n\n\u003c!-- /MarkdownTOC --\u003e\n\n## Basic Usage\n\n```js\n// widgetsDuck.js\n\nimport Duck from 'extensible-duck'\n\nexport default new Duck({\n  namespace: 'my-app', store: 'widgets',\n  types: ['LOAD', 'CREATE', 'UPDATE', 'REMOVE'],\n  initialState: {},\n  reducer: (state, action, duck) =\u003e {\n    switch(action.type) {\n      // do reducer stuff\n      default: return state\n    }\n  },\n  selectors: {\n    root: state =\u003e state\n  },\n  creators: (duck) =\u003e ({\n    loadWidgets:      () =\u003e ({ type: duck.types.LOAD }),\n    createWidget: widget =\u003e ({ type: duck.types.CREATE, widget }),\n    updateWidget: widget =\u003e ({ type: duck.types.UPDATE, widget }),\n    removeWidget: widget =\u003e ({ type: duck.types.REMOVE, widget })\n  })\n})\n```\n\n```js\n// reducers.js\n\nimport { combineReducers } from 'redux'\nimport widgetDuck from './widgetDuck'\n\nexport default combineReducers({ [widgetDuck.store]: widgetDuck.reducer })\n```\n\n### Constructor Arguments\n\nconst { namespace, store, types, consts, initialState, creators } = options\n\n| Name         | Description                                             | Type                           | Example                                     |\n|--------------|---------------------------------------------------------|--------------------------------|---------------------------------------------|\n| namespace    | Used as a prefix for the types                          | String                         | `'my-app'`                                  |\n| store        | Used as a prefix for the types and as a redux state key | String                         | `'widgets'`                                 |\n| storePath    | Object path of the store from root infinal redux state.  Defaults to the [duck.store] value.  Can be used to define duck store location in nested state  | String                         | `'foo.bar'`                                 |\n| types        | List of action types                                    | Array                          | `[ 'CREATE', 'UPDATE' ]`                    |\n| consts       | Constants you may need to declare                       | Object of Arrays               | `{ statuses: [ 'LOADING', 'LOADED' ] }`     |\n| initialState | State passed to the reducer when the state is undefined | Anything                       | `{}`                                        |\n| reducer      | Action reducer                                          | function(state, action, duck)  | `(state, action, duck) =\u003e { return state }` |\n| creators     | Action creators                                         | function(duck)                 | `duck =\u003e ({ type: types.CREATE })`          |\n| sagas        | Action sagas                                            | function(duck)                 | `duck =\u003e ({ fetchData: function* { yield ... }` |\n| takes        | Action takes                                            | function(duck)                 | `duck =\u003e ([ takeEvery(types.FETCH, sagas.fetchData) ])` |\n| selectors    | state selectors                                         | Object of functions\u003cbr\u003eor\u003cbr\u003efunction(duck) | `{ root: state =\u003e state}`\u003cbr\u003eor\u003cbr\u003e`duck =\u003e ({ root: state =\u003e state })` |\n\n### Duck Accessors\n\n * duck.store\n * duck.storePath\n * duck.reducer\n * duck.creators\n * duck.sagas\n * duck.takes\n * duck.selectors\n * duck.types\n * for each const, duck.\\\u003cconst\\\u003e\n\n### Helper functions\n\n * **constructLocalized(selectors)**: maps selectors syntax from `(globalStore) =\u003e selectorBody` into `(localStore, globalStore) =\u003e selectorBody`. `localStore` is derived from `globalStore` on every selector execution using `duck.storage` key. Use to simplify selectors syntax when used in tandem with reduxes' `combineReducers` to bind the duck to a dedicated state part ([example](#creating-ducks-with-selectors)).  If defined will use the duck.storePath value to determine the localized state in deeply nested redux state trees.\n\n### Defining the Reducer\n\nWhile a plain vanilla reducer would be defined by something like this:\n\n```js\nfunction reducer(state={}, action) {\n  switch (action.type) {\n    // ...\n    default:\n      return state\n  }\n}\n```\n\nHere the reducer has two slight differences:\n\n * It receives the duck itself as the third argument\n * It doesn't define the initial state (see [Defining the Initial State](#defining-the-initial-state))\n\n```js\nnew Duck({\n  // ...\n  reducer: (state, action, duck) =\u003e {\n    switch (action.type) {\n      // ...\n      default:\n        return state\n    }\n  }\n})\n```\n\nWith the `duck` argument you can access the types, the constants, etc (see [Duck Accessors](#duck-accessors)).\n\n### Defining the Creators\n\nWhile plain vanilla creators would be defined by something like this:\n\n```js\nexport function createWidget(widget) {\n  return { type: CREATE, widget }\n}\n\n// Using thunk\nexport function updateWidget(widget) {\n  return dispatch =\u003e {\n    dispatch({ type: UPDATE, widget })\n  }\n}\n```\n\nWith extensible-duck you define it as an Object of functions:\n\n```js\nexport default new Duck({\n  // ...\n  creators: {\n    createWidget: widget =\u003e ({ type: 'CREATE', widget })\n\n    // Using thunk\n    updateWidget: widget =\u003e dispatch =\u003e {\n      dispatch({ type: 'UPDATE', widget })\n    }\n  }\n})\n```\n\nIf you need to access any duck attribute, you can define a function that returns the Object of functions:\n\n```js\nexport default new Duck({\n  // ...\n  types: [ 'CREATE' ],\n  creators: (duck) =\u003e ({\n    createWidget: widget =\u003e ({ type: duck.types.CREATE, widget })\n  })\n})\n```\n\n### Defining the Sagas\n\nWhile plain vanilla creators would be defined by something like this:\n\n```js\nfunction* fetchData() {\n  try{\n  \tyield put({ type: reducerDuck.types.FETCH_PENDING })\n    const payload = yield call(Get, 'data')\n    yield put({\n      type: reducerDuck.types.FETCH_FULFILLED,\n      payload\n    })\n  } catch(err) {\n    yield put({\n      type: reducerDuck.types.FETCH_FAILURE,\n      err\n    })\n  }\n}\n\n// Defining observer\nexport default [ takeEvery(reducerDuck.types.FETCH, fetchData) ]\n```\n\nWith extensible-duck you define it as an Object of functions accessing any duck attribute:\n\n```js\nexport default new Duck({\n  // ...\n  sagas: {\n    fetchData: function* (duck) {\n    \ttry{\n        yield put({ type: duck.types.FETCH_PENDING })\n        const payload = yield call(Get, 'data')\n        yield put({\n          type: duck.types.FETCH_FULFILLED,\n          payload\n        })\n      } catch(err) {\n        yield put({\n          type: duck.types.FETCH_FAILURE,\n          err\n        })\n      }\n    }\n  },\n  // Defining observer\n  takes: (duck) =\u003e ([\n  \ttakeEvery(duck.types.FETCH, duck.sagas.fetchData)\n  ])\n})\n```\n\n### Defining the Initial State\n\nUsually the initial state is declared within the the reducer declaration, just like bellow:\n\n```js\nfunction myReducer(state = {someDefaultValue}, action) {\n  // ...\n}\n```\n\nWith extensible-duck you define it separately:\n\n```js\nexport default new Duck({\n  // ...\n  initialState: {someDefaultValue}\n})\n```\n\nIf you need to access the [types](#defining-the-types) or [constants](#defining-the-constants), you can define this way:\n\n```js\nexport default new Duck({\n  // ...\n  consts: { statuses: ['NEW'] },\n  initialState: ({ statuses }) =\u003e ({ status: statuses.NEW })\n})\n```\n\n### Defining the Selectors\n\nSimple selectors:\n\n```js\nexport default new Duck({\n  // ...\n  selectors: {\n    shopItems:  state =\u003e state.shop.items\n  }\n})\n\n```\n\nComposed selectors:\n\n```js\nexport default new Duck({\n  // ...\n  selectors: {\n    shopItems:  state =\u003e state.shop.items,\n    subtotal: new Duck.Selector(selectors =\u003e state =\u003e\n      selectors.shopItems(state).reduce((acc, item) =\u003e acc + item.value, 0)\n    )\n  }\n})\n```\n\nUsing with [Reselect](https://github.com/reactjs/reselect):\n\n```js\nexport default new Duck({\n  // ...\n  selectors: {\n    shopItems:  state =\u003e state.shop.items,\n    subtotal: new Duck.Selector(selectors =\u003e\n      createSelector(\n        selectors.shopItems,\n        items =\u003e items.reduce((acc, item) =\u003e acc + item.value, 0)\n      )\n    )\n  }\n})\n```\n\nSelectors with duck reference:\n\n```js\nexport default new Duck({\n  // ...\n  selectors: (duck) =\u003e ({\n    shopItems:  state =\u003e state.shop.items,\n    addedItems: new Duck.Selector(selectors =\u003e\n      createSelector(\n        selectors.shopItems,\n        items =\u003e {\n          const out = [];\n          items.forEach(item =\u003e {\n            if (-1 === duck.initialState.shop.items.indexOf(item)) {\n              out.push(item);\n            }\n          });\n          return out;\n        }\n      )\n    )\n  })\n})\n```\n\n### Defining the Types\n\n```js\nexport default new Duck({\n  namespace: 'my-app', store: 'widgets',\n  // ...\n  types: [\n    'CREATE',   // myDuck.types.CREATE   = \"my-app/widgets/CREATE\"\n    'RETREIVE', // myDuck.types.RETREIVE = \"my-app/widgets/RETREIVE\"\n    'UPDATE',   // myDuck.types.UPDATE   = \"my-app/widgets/UPDATE\"\n    'DELETE',   // myDuck.types.DELETE   = \"my-app/widgets/DELETE\"\n  ]\n}\n```\n\n### Defining the Constants\n\n```js\nexport default new Duck({\n  // ...\n  consts: {\n    statuses: ['NEW'], // myDuck.statuses = { NEW: \"NEW\" }\n    fooBar: [\n      'FOO',           // myDuck.fooBar.FOO = \"FOO\"\n      'BAR'            // myDuck.fooBar.BAR = \"BAR\"\n    ]\n  }\n}\n```\n\n## Creating Reusable Ducks\n\nThis example uses [redux-promise-middleware](https://github.com/pburtchaell/redux-promise-middleware)\nand [axios](https://github.com/mzabriskie/axios).\n\n```js\n// remoteObjDuck.js\n\nimport Duck from 'extensible-duck'\nimport axios from 'axios'\n\nexport default function createDuck({ namespace, store, path, initialState={} }) {\n  return new Duck({\n    namespace, store,\n\n    consts: { statuses: [ 'NEW', 'LOADING', 'READY', 'SAVING', 'SAVED' ] },\n\n    types: [\n      'UPDATE',\n      'FETCH', 'FETCH_PENDING',  'FETCH_FULFILLED',\n      'POST',  'POST_PENDING',   'POST_FULFILLED',\n    ],\n\n    reducer: (state, action, { types, statuses, initialState }) =\u003e {\n      switch(action.type) {\n        case types.UPDATE:\n          return { ...state, obj: { ...state.obj, ...action.payload } }\n        case types.FETCH_PENDING:\n          return { ...state, status: statuses.LOADING }\n        case types.FETCH_FULFILLED:\n          return { ...state, obj: action.payload.data, status: statuses.READY }\n        case types.POST_PENDING:\n        case types.PATCH_PENDING:\n          return { ...state, status: statuses.SAVING }\n        case types.POST_FULFILLED:\n        case types.PATCH_FULFILLED:\n          return { ...state, status: statuses.SAVED }\n        default:\n          return state\n      }\n    },\n\n    creators: ({ types }) =\u003e ({\n      update: (fields) =\u003e ({ type: types.UPDATE, payload: fields }),\n      get:        (id) =\u003e ({ type: types.FETCH, payload: axios.get(`${path}/${id}`),\n      post:         () =\u003e ({ type: types.POST, payload: axios.post(path, obj) }),\n      patch:        () =\u003e ({ type: types.PATCH, payload: axios.patch(`${path}/${id}`, obj) })\n    }),\n\n    initialState: ({ statuses }) =\u003e ({ obj: initialState || {}, status: statuses.NEW, entities: [] })\n  })\n}\n```\n\n```js\n// usersDuck.js\n\nimport createDuck from './remoteObjDuck'\n\nexport default createDuck({ namespace: 'my-app', store: 'user', path: '/users' })\n```\n\n```js\n// reducers.js\n\nimport { combineReducers } from 'redux'\nimport userDuck from './userDuck'\n\nexport default combineReducers({ [userDuck.store]: userDuck.reducer })\n```\n\n## Extending Ducks\n\nThis example is based on the previous one.\n\n```js\n// usersDuck.js\n\nimport createDuck from './remoteObjDuck.js'\n\nexport default createDuck({ namespace: 'my-app',store: 'user', path: '/users' }).extend({\n  types: [ 'RESET' ],\n  reducer: (state, action, { types, statuses, initialState }) =\u003e {\n    switch(action.type) {\n      case types.RESET:\n        return { ...initialState, obj: { ...initialState.obj, ...action.payload } }\n      default:\n        return state\n  },\n  creators: ({ types }) =\u003e ({\n    reset: (fields) =\u003e ({ type: types.RESET, payload: fields }),\n  })\n})\n```\n\n## Creating Reusable Duck Extensions\n\nThis example is a refactor of the previous one.\n\n```js\n// resetDuckExtension.js\n\nexport default {\n  types: [ 'RESET' ],\n  reducer: (state, action, { types, statuses, initialState }) =\u003e {\n    switch(action.type) {\n      case types.RESET:\n        return { ...initialState, obj: { ...initialState.obj, ...action.payload } }\n      default:\n        return state\n  },\n  creators: ({ types }) =\u003e ({\n    reset: (fields) =\u003e ({ type: types.RESET, payload: fields }),\n  })\n}\n```\n\n```js\n// userDuck.js\n\nimport createDuck from './remoteObjDuck'\nimport reset from './resetDuckExtension'\n\nexport default createDuck({ namespace: 'my-app',store: 'user', path: '/users' }).extend(reset)\n```\n\n\n## Creating Ducks with selectors\n\nSelectors help in providing performance optimisations when used with libraries such as React-Redux, Preact-Redux etc.\n\n```js\n// Duck.js\n\nimport Duck, { constructLocalized } from 'extensible-duck'\n\nexport default new Duck({\n  store: 'fruits',\n  initialState: {\n    items: [\n      { name: 'apple', value: 1.2 },\n      { name: 'orange', value: 0.95 }\n    ]\n  },\n  reducer: (state, action, duck) =\u003e {\n    switch(action.type) {\n      // do reducer stuff\n      default: return state\n    }\n  },\n  selectors: constructLocalized({\n    items: state =\u003e state.items, // gets the items from state\n    subTotal: new Duck.Selector(selectors =\u003e state =\u003e\n      // Get another derived state reusing previous selector. In this case items selector\n      // Can compose multiple such selectors if using library like reselect. Recommended!\n      // Note: The order of the selectors definitions matters\n      selectors\n        .items(state)\n        .reduce((computedTotal, item) =\u003e computedTotal + item.value, 0)\n    )\n  })\n})\n```\n\n```js\n// reducers.js\n\nimport { combineReducers } from 'redux'\nimport Duck from './Duck'\n\nexport default combineReducers({ [Duck.store]: Duck.reducer })\n```\n\n```js\n// HomeView.js\nimport React from 'react'\nimport Duck from './Duck'\n\n@connect(state =\u003e ({\n  items: Duck.selectors.items(state),\n  subTotal: Duck.selectors.subTotal(state)\n}))\nexport default class HomeView extends React.Component {\n  render(){\n    // make use of sliced state here in props\n    ...\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finvesttools%2Fextensible-duck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finvesttools%2Fextensible-duck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finvesttools%2Fextensible-duck/lists"}