From 2e357b71e233b9374524b1e2baa199bf54445980 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Tue, 12 Oct 2021 14:49:08 -0400 Subject: [PATCH] wip --- {tsdocs => docs/API}/.nojekyll | 0 docs/API/README.md | 228 ----- {tsdocs => docs/API}/assets/highlight.css | 0 {tsdocs => docs/API}/assets/icons.css | 0 {tsdocs => docs/API}/assets/icons.png | Bin {tsdocs => docs/API}/assets/icons@2x.png | Bin {tsdocs => docs/API}/assets/main.js | 0 docs/API/assets/search.js | 1 + {tsdocs => docs/API}/assets/style.css | 0 {tsdocs => docs/API}/assets/widgets.png | Bin {tsdocs => docs/API}/assets/widgets@2x.png | Bin docs/API/classes/_updux_.Updux.html | 1 + docs/API/classes/updux.md | 491 ---------- docs/API/globals.md | 980 ------------------- {tsdocs => docs/API}/index.html | 4 +- docs/API/interfaces/_updux_.UpduxConfig.html | 25 + docs/API/modules.html | 1 + docs/API/modules/_updux_.html | 1 + docs/index.html | 152 +-- pagesconfig.json | 13 + src/Updux.d.ts | 20 + src/index.d.ts | 1 + tsconfig.json | 15 +- tsdocs/assets/search.js | 1 - tsdocs/modules.html | 1 - typedoc.json | 15 + types/index.d.ts | 73 +- 27 files changed, 170 insertions(+), 1853 deletions(-) rename {tsdocs => docs/API}/.nojekyll (100%) delete mode 100644 docs/API/README.md rename {tsdocs => docs/API}/assets/highlight.css (100%) rename {tsdocs => docs/API}/assets/icons.css (100%) rename {tsdocs => docs/API}/assets/icons.png (100%) rename {tsdocs => docs/API}/assets/icons@2x.png (100%) rename {tsdocs => docs/API}/assets/main.js (100%) create mode 100644 docs/API/assets/search.js rename {tsdocs => docs/API}/assets/style.css (100%) rename {tsdocs => docs/API}/assets/widgets.png (100%) rename {tsdocs => docs/API}/assets/widgets@2x.png (100%) create mode 100644 docs/API/classes/_updux_.Updux.html delete mode 100644 docs/API/classes/updux.md delete mode 100644 docs/API/globals.md rename {tsdocs => docs/API}/index.html (95%) create mode 100644 docs/API/interfaces/_updux_.UpduxConfig.html create mode 100644 docs/API/modules.html create mode 100644 docs/API/modules/_updux_.html create mode 100644 pagesconfig.json create mode 100644 src/Updux.d.ts create mode 100644 src/index.d.ts delete mode 100644 tsdocs/assets/search.js delete mode 100644 tsdocs/modules.html create mode 100644 typedoc.json diff --git a/tsdocs/.nojekyll b/docs/API/.nojekyll similarity index 100% rename from tsdocs/.nojekyll rename to docs/API/.nojekyll diff --git a/docs/API/README.md b/docs/API/README.md deleted file mode 100644 index 9222c85..0000000 --- a/docs/API/README.md +++ /dev/null @@ -1,228 +0,0 @@ -[updux - v1.2.0](README.md) › [Globals](globals.md) - -# updux - v1.2.0 - -# What's Updux? - -So, I'm a fan of [Redux](https://redux.js.org). Two days ago I discovered -[rematch](https://rematch.github.io/rematch) alonside a few other frameworks built atop Redux. - -It has a couple of pretty good ideas that removes some of the -boilerplate. Keeping mutations and asynchronous effects close to the -reducer definition? Nice. Automatically infering the -actions from the said mutations and effects? Genius! - -But it also enforces a flat hierarchy of reducers -- where -is the fun in that? And I'm also having a strong love for -[Updeep](https://github.com/substantial/updeep), so I want reducer state updates to leverage the heck out of it. - -All that to say, say hello to `Updux`. Heavily inspired by `rematch`, but twisted -to work with `updeep` and to fit my peculiar needs. It offers features such as - -* Mimic the way VueX has mutations (reducer reactions to specific actions) and - effects (middleware reacting to actions that can be asynchronous and/or - have side-effects), so everything pertaining to a store are all defined - in the space place. -* Automatically gather all actions used by the updux's effects and mutations, - and makes then accessible as attributes to the `dispatch` object of the - store. -* Mutations have a signature that is friendly to Updux and Immer. -* Also, the mutation signature auto-unwrap the payload of the actions for you. -* TypeScript types. - -Fair warning: this package is still very new, probably very buggy, -definitively very badly documented, and very subject to changes. Caveat -Maxima Emptor. - -# Synopsis - -``` -import updux from 'updux'; - -import otherUpdux from './otherUpdux'; - -const { - initial, - reducer, - actions, - middleware, - createStore, -} = new Updux({ - initial: { - counter: 0, - }, - subduxes: { - otherUpdux, - }, - mutations: { - inc: ( increment = 1 ) => u({counter: s => s + increment }) - }, - effects: { - '*' => api => next => action => { - console.log( "hey, look, an action zoomed by!", action ); - next(action); - }; - }, - actions: { - customAction: ( someArg ) => ({ - type: "custom", - payload: { someProp: someArg } - }), - }, - -}); - -const store = createStore(); - -store.dispatch.inc(3); -``` - -# Description - -Full documentation can be [found here](https://yanick.github.io/updux/docs/). - -## Exporting upduxes - -If you are creating upduxes that will be used as subduxes -by other upduxes, or as -[ducks](https://github.com/erikras/ducks-modular-redux)-like containers, I -recommend that you export the Updux instance as the default export: - -``` -import Updux from 'updux'; - -const updux = new Updux({ ... }); - -export default updux; -``` - -Then you can use them as subduxes like this: - -``` -import Updux from 'updux'; -import foo from './foo'; // foo is an Updux -import bar from './bar'; // bar is an Updux as well - -const updux = new Updux({ - subduxes: { - foo, bar - } -}); -``` - -Or if you want to use it: - -``` -import updux from './myUpdux'; - -const { - reducer, - actions: { doTheThing }, - createStore, - middleware, -} = updux; -``` - -## Mapping a mutation to all values of a state - -Say you have a `todos` state that is an array of `todo` sub-states. It's easy -enough to have the main reducer maps away all items to the sub-reducer: - -``` -const todo = new Updux({ - mutations: { - review: () => u({ reviewed: true}), - done: () => u({done: true}), - }, -}); - -const todos = new Updux({ initial: [] }); - -todos.addMutation( - todo.actions.review, - (_,action) => state => state.map( todo.upreducer(action) ) -); -todos.addMutation( - todo.actions.done, - (id,action) => u.map(u.if(u.is('id',id), todo.upreducer(action))), -); - -``` - -But `updeep` can iterate through all the items of an array (or the values of -an object) via the special key `*`. So the todos updux above could also be -written: - -``` -const todo = new Updux({ - mutations: { - review: () => u({ reviewed: true}), - done: () => u({done: true}), - }, -}); - -const todos = new Updux({ - subduxes: { '*': todo }, -}); - -todos.addMutation( - todo.actions.done, - (id,action) => u.map(u.if(u.is('id',id), todo.upreducer(action))), - true -); -``` - -The advantages being that the actions/mutations/effects of the subdux will be -imported by the root updux as usual, and all actions that aren't being -overridden by a sink mutation will trickle down automatically. - -## Usage with Immer - -While Updux was created with Updeep in mind, it also plays very -well with [Immer](https://immerjs.github.io/immer/docs/introduction). - -For example, taking this basic updux: - -``` -import Updux from 'updux'; - -const updux = new Updux({ - initial: { counter: 0 }, - mutations: { - add: (inc=1) => state => { counter: counter + inc } - } -}); - -``` - -Converting it to Immer would look like: - -``` -import Updux from 'updux'; -import { produce } from 'Immer'; - -const updux = new Updux({ - initial: { counter: 0 }, - mutations: { - add: (inc=1) => produce( draft => draft.counter += inc ) } - } -}); - -``` - -But since typing `produce` over and over is no fun, `groomMutations` -can be used to wrap all mutations with it: - -``` -import Updux from 'updux'; -import { produce } from 'Immer'; - -const updux = new Updux({ - initial: { counter: 0 }, - groomMutations: mutation => (...args) => produce( mutation(...args) ), - mutations: { - add: (inc=1) => draft => draft.counter += inc - } -}); - -``` diff --git a/tsdocs/assets/highlight.css b/docs/API/assets/highlight.css similarity index 100% rename from tsdocs/assets/highlight.css rename to docs/API/assets/highlight.css diff --git a/tsdocs/assets/icons.css b/docs/API/assets/icons.css similarity index 100% rename from tsdocs/assets/icons.css rename to docs/API/assets/icons.css diff --git a/tsdocs/assets/icons.png b/docs/API/assets/icons.png similarity index 100% rename from tsdocs/assets/icons.png rename to docs/API/assets/icons.png diff --git a/tsdocs/assets/icons@2x.png b/docs/API/assets/icons@2x.png similarity index 100% rename from tsdocs/assets/icons@2x.png rename to docs/API/assets/icons@2x.png diff --git a/tsdocs/assets/main.js b/docs/API/assets/main.js similarity index 100% rename from tsdocs/assets/main.js rename to docs/API/assets/main.js diff --git a/docs/API/assets/search.js b/docs/API/assets/search.js new file mode 100644 index 0000000..aaea63e --- /dev/null +++ b/docs/API/assets/search.js @@ -0,0 +1 @@ +window.searchData = {"kinds":{"4":"Namespace","128":"Class","256":"Interface","512":"Constructor","1024":"Property","262144":"Accessor","4194304":"Type alias"},"rows":[{"id":0,"kind":4194304,"name":"Dict","url":"modules.html#Dict","classes":"tsd-kind-type-alias tsd-has-type-parameter"},{"id":1,"kind":4,"name":"\"updux\"","url":"modules/_updux_.html","classes":"tsd-kind-namespace"},{"id":2,"kind":256,"name":"UpduxConfig","url":"interfaces/_updux_.UpduxConfig.html","classes":"tsd-kind-interface tsd-parent-kind-namespace tsd-has-type-parameter","parent":"\"updux\""},{"id":3,"kind":1024,"name":"initial","url":"interfaces/_updux_.UpduxConfig.html#initial","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":4,"kind":1024,"name":"subduxes","url":"interfaces/_updux_.UpduxConfig.html#subduxes","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":5,"kind":1024,"name":"actions","url":"interfaces/_updux_.UpduxConfig.html#actions","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":6,"kind":1024,"name":"selectors","url":"interfaces/_updux_.UpduxConfig.html#selectors","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":7,"kind":1024,"name":"mutations","url":"interfaces/_updux_.UpduxConfig.html#mutations","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":8,"kind":1024,"name":"mappedSelectors","url":"interfaces/_updux_.UpduxConfig.html#mappedSelectors","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":9,"kind":1024,"name":"effects","url":"interfaces/_updux_.UpduxConfig.html#effects","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":10,"kind":1024,"name":"reactions","url":"interfaces/_updux_.UpduxConfig.html#reactions","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":11,"kind":1024,"name":"mappedReaction","url":"interfaces/_updux_.UpduxConfig.html#mappedReaction","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":12,"kind":128,"name":"Updux","url":"classes/_updux_.Updux.html","classes":"tsd-kind-class tsd-parent-kind-namespace tsd-has-type-parameter","parent":"\"updux\""},{"id":13,"kind":512,"name":"constructor","url":"classes/_updux_.Updux.html#constructor","classes":"tsd-kind-constructor tsd-parent-kind-class tsd-has-type-parameter","parent":"\"updux\".Updux"},{"id":14,"kind":262144,"name":"initial","url":"classes/_updux_.Updux.html#initial","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"\"updux\".Updux"},{"id":15,"kind":262144,"name":"selectors","url":"classes/_updux_.Updux.html#selectors","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"\"updux\".Updux"}],"index":{"version":"2.3.9","fields":["name","parent"],"fieldVectors":[["name/0",[0,24.277]],["parent/0",[]],["name/1",[1,13.291]],["parent/1",[]],["name/2",[2,24.277]],["parent/2",[1,1.256]],["name/3",[3,19.169]],["parent/3",[4,0.55]],["name/4",[5,24.277]],["parent/4",[4,0.55]],["name/5",[6,24.277]],["parent/5",[4,0.55]],["name/6",[7,19.169]],["parent/6",[4,0.55]],["name/7",[8,24.277]],["parent/7",[4,0.55]],["name/8",[9,24.277]],["parent/8",[4,0.55]],["name/9",[10,24.277]],["parent/9",[4,0.55]],["name/10",[11,24.277]],["parent/10",[4,0.55]],["name/11",[12,24.277]],["parent/11",[4,0.55]],["name/12",[1,13.291]],["parent/12",[1,1.256]],["name/13",[13,24.277]],["parent/13",[14,1.493]],["name/14",[3,19.169]],["parent/14",[14,1.493]],["name/15",[7,19.169]],["parent/15",[14,1.493]]],"invertedIndex":[["actions",{"_index":6,"name":{"5":{}},"parent":{}}],["constructor",{"_index":13,"name":{"13":{}},"parent":{}}],["dict",{"_index":0,"name":{"0":{}},"parent":{}}],["effects",{"_index":10,"name":{"9":{}},"parent":{}}],["initial",{"_index":3,"name":{"3":{},"14":{}},"parent":{}}],["mappedreaction",{"_index":12,"name":{"11":{}},"parent":{}}],["mappedselectors",{"_index":9,"name":{"8":{}},"parent":{}}],["mutations",{"_index":8,"name":{"7":{}},"parent":{}}],["reactions",{"_index":11,"name":{"10":{}},"parent":{}}],["selectors",{"_index":7,"name":{"6":{},"15":{}},"parent":{}}],["subduxes",{"_index":5,"name":{"4":{}},"parent":{}}],["updux",{"_index":1,"name":{"1":{},"12":{}},"parent":{"2":{},"12":{}}}],["updux\".updux",{"_index":14,"name":{},"parent":{"13":{},"14":{},"15":{}}}],["updux\".upduxconfig",{"_index":4,"name":{},"parent":{"3":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{},"10":{},"11":{}}}],["upduxconfig",{"_index":2,"name":{"2":{}},"parent":{}}]],"pipeline":[]}} \ No newline at end of file diff --git a/tsdocs/assets/style.css b/docs/API/assets/style.css similarity index 100% rename from tsdocs/assets/style.css rename to docs/API/assets/style.css diff --git a/tsdocs/assets/widgets.png b/docs/API/assets/widgets.png similarity index 100% rename from tsdocs/assets/widgets.png rename to docs/API/assets/widgets.png diff --git a/tsdocs/assets/widgets@2x.png b/docs/API/assets/widgets@2x.png similarity index 100% rename from tsdocs/assets/widgets@2x.png rename to docs/API/assets/widgets@2x.png diff --git a/docs/API/classes/_updux_.Updux.html b/docs/API/classes/_updux_.Updux.html new file mode 100644 index 0000000..dd48f2b --- /dev/null +++ b/docs/API/classes/_updux_.Updux.html @@ -0,0 +1 @@ +Updux
Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Updux<TState>

Type parameters

  • TState = unknown

Hierarchy

  • Updux

Index

Constructors

Accessors

Constructors

constructor

  • Type parameters

    • TState = unknown

    Parameters

    Returns Updux<TState>

Accessors

initial

  • get initial(): TState
  • Returns TState

selectors

  • get selectors(): unknown
  • Returns unknown

Generated using TypeDoc

\ No newline at end of file diff --git a/docs/API/classes/updux.md b/docs/API/classes/updux.md deleted file mode 100644 index 5a7a2a1..0000000 --- a/docs/API/classes/updux.md +++ /dev/null @@ -1,491 +0,0 @@ -[updux - v1.2.0](../README.md) › [Globals](../globals.md) › [Updux](updux.md) - -# Class: Updux <**S, A, X, C**> - -## Type parameters - -▪ **S** - -▪ **A** - -▪ **X** - -▪ **C**: *[UpduxConfig](../globals.md#upduxconfig)* - -## Hierarchy - -* **Updux** - -## Index - -### Constructors - -* [constructor](updux.md#constructor) - -### Properties - -* [coduxes](updux.md#coduxes) -* [groomMutations](updux.md#groommutations) -* [subduxes](updux.md#subduxes) - -### Accessors - -* [_middlewareEntries](updux.md#_middlewareentries) -* [actions](updux.md#actions) -* [asDux](updux.md#asdux) -* [createStore](updux.md#createstore) -* [initial](updux.md#initial) -* [middleware](updux.md#middleware) -* [mutations](updux.md#mutations) -* [reducer](updux.md#reducer) -* [selectors](updux.md#selectors) -* [subduxUpreducer](updux.md#subduxupreducer) -* [upreducer](updux.md#upreducer) - -### Methods - -* [addAction](updux.md#addaction) -* [addEffect](updux.md#addeffect) -* [addMutation](updux.md#addmutation) -* [addSelector](updux.md#addselector) - -## Constructors - -### constructor - -\+ **new Updux**(`config`: C): *[Updux](updux.md)* - -**Parameters:** - -Name | Type | Default | Description | ------- | ------ | ------ | ------ | -`config` | C | {} as C | an [UpduxConfig](../globals.md#upduxconfig) plain object | - -**Returns:** *[Updux](updux.md)* - -## Properties - -### coduxes - -• **coduxes**: *[Dux](../globals.md#dux)[]* - -___ - -### groomMutations - -• **groomMutations**: *function* - -#### Type declaration: - -▸ (`mutation`: [Mutation](../globals.md#mutation)‹S›): *[Mutation](../globals.md#mutation)‹S›* - -**Parameters:** - -Name | Type | ------- | ------ | -`mutation` | [Mutation](../globals.md#mutation)‹S› | - -___ - -### subduxes - -• **subduxes**: *[Dictionary](../globals.md#dictionary)‹[Dux](../globals.md#dux)›* - -## Accessors - -### _middlewareEntries - -• **get _middlewareEntries**(): *any[]* - -**Returns:** *any[]* - -___ - -### actions - -• **get actions**(): *[DuxActions](../globals.md#duxactions)‹A, C›* - -Action creators for all actions defined or used in the actions, mutations, effects and subduxes -of the updux config. - -Non-custom action creators defined in `actions` have the signature `(payload={},meta={}) => ({type, -payload,meta})` (with the extra sugar that if `meta` or `payload` are not -specified, that key won't be present in the produced action). - -The same action creator can be included -in multiple subduxes. However, if two different creators -are included for the same action, an error will be thrown. - -**`example`** - -``` -const actions = updux.actions; -``` - -**Returns:** *[DuxActions](../globals.md#duxactions)‹A, C›* - -___ - -### asDux - -• **get asDux**(): *object* - -Returns a ducks-like -plain object holding the reducer from the Updux object and all -its trimmings. - -**`example`** - -``` -const { - createStore, - upreducer, - subduxes, - coduxes, - middleware, - actions, - reducer, - mutations, - initial, - selectors, -} = myUpdux.asDux; -``` - -**Returns:** *object* - -* **actions**: = this.actions - -* **coduxes**: *object[]* = this.coduxes - -* **createStore**(): *function* - - * (`initial?`: S, `injectEnhancer?`: Function): *Store‹S› & object* - -* **initial**: = this.initial - -* **middleware**(): *function* - - * (`api`: UpduxMiddlewareAPI‹S, X›): *function* - - * (`next`: Function): *function* - - * (`action`: A): *any* - -* **mutations**(): *object* - -* **reducer**(): *function* - - * (`state`: S | undefined, `action`: [Action](../globals.md#action)): *S* - -* **selectors**: = this.selectors - -* **subduxes**(): *object* - -* **upreducer**(): *function* - - * (`action`: [Action](../globals.md#action)): *function* - - * (`state`: S): *S* - -___ - -### createStore - -• **get createStore**(): *function* - -Returns a `createStore` function that takes two argument: -`initial` and `injectEnhancer`. `initial` is a custom -initial state for the store, and `injectEnhancer` is a function -taking in the middleware built by the updux object and allowing -you to wrap it in any enhancer you want. - -**`example`** - -``` -const createStore = updux.createStore; - -const store = createStore(initial); -``` - -**Returns:** *function* - -▸ (`initial?`: S, `injectEnhancer?`: Function): *Store‹S› & object* - -**Parameters:** - -Name | Type | ------- | ------ | -`initial?` | S | -`injectEnhancer?` | Function | - -___ - -### initial - -• **get initial**(): *AggDuxState‹S, C›* - -**Returns:** *AggDuxState‹S, C›* - -___ - -### middleware - -• **get middleware**(): *[UpduxMiddleware](../globals.md#upduxmiddleware)‹AggDuxState‹S, C›, [DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C››* - -Array of middlewares aggregating all the effects defined in the -updux and its subduxes. Effects of the updux itself are -done before the subduxes effects. -Note that `getState` will always return the state of the -local updux. - -**`example`** - -``` -const middleware = updux.middleware; -``` - -**Returns:** *[UpduxMiddleware](../globals.md#upduxmiddleware)‹AggDuxState‹S, C›, [DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C››* - -___ - -### mutations - -• **get mutations**(): *[Dictionary](../globals.md#dictionary)‹[Mutation](../globals.md#mutation)‹S››* - -Merge of the updux and subduxes mutations. If an action triggers -mutations in both the main updux and its subduxes, the subduxes -mutations will be performed first. - -**Returns:** *[Dictionary](../globals.md#dictionary)‹[Mutation](../globals.md#mutation)‹S››* - -___ - -### reducer - -• **get reducer**(): *function* - -A Redux reducer generated using the computed initial state and -mutations. - -**Returns:** *function* - -▸ (`state`: S | undefined, `action`: [Action](../globals.md#action)): *S* - -**Parameters:** - -Name | Type | ------- | ------ | -`state` | S | undefined | -`action` | [Action](../globals.md#action) | - -___ - -### selectors - -• **get selectors**(): *[DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C›* - -A dictionary of the updux's selectors. Subduxes' -selectors are included as well (with the mapping to the -sub-state already taken care of you). - -**Returns:** *[DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C›* - -___ - -### subduxUpreducer - -• **get subduxUpreducer**(): *function* - -Returns the upreducer made of the merge of all sudbuxes reducers, without -the local mutations. Useful, for example, for sink mutations. - -**`example`** - -``` -import todo from './todo'; // updux for a single todo -import Updux from 'updux'; -import u from 'updeep'; - -const todos = new Updux({ initial: [], subduxes: { '*': todo } }); -todos.addMutation( - todo.actions.done, - ({todo_id},action) => u.map( u.if( u.is('id',todo_id) ), todos.subduxUpreducer(action) ) - true -); -``` - -**Returns:** *function* - -▸ (`action`: [Action](../globals.md#action)): *function* - -**Parameters:** - -Name | Type | ------- | ------ | -`action` | [Action](../globals.md#action) | - -▸ (`state`: S): *S* - -**Parameters:** - -Name | Type | ------- | ------ | -`state` | S | - -___ - -### upreducer - -• **get upreducer**(): *[Upreducer](../globals.md#upreducer)‹S›* - -**Returns:** *[Upreducer](../globals.md#upreducer)‹S›* - -## Methods - -### addAction - -▸ **addAction**(`theaction`: string, `transform?`: any): *ActionCreator‹string, any›* - -Adds an action to the updux. It can take an already defined action -creator, or any arguments that can be passed to `actionCreator`. - -**`example`** -``` - const action = updux.addAction( name, ...creatorArgs ); - const action = updux.addAction( otherActionCreator ); -``` - -**`example`** -``` -import {actionCreator, Updux} from 'updux'; - -const updux = new Updux(); - -const foo = updux.addAction('foo'); -const bar = updux.addAction( 'bar', (x) => ({stuff: x+1}) ); - -const baz = actionCreator( 'baz' ); - -foo({ a: 1}); // => { type: 'foo', payload: { a: 1 } } -bar(2); // => { type: 'bar', payload: { stuff: 3 } } -baz(); // => { type: 'baz', payload: undefined } -``` - -**Parameters:** - -Name | Type | ------- | ------ | -`theaction` | string | -`transform?` | any | - -**Returns:** *ActionCreator‹string, any›* - -▸ **addAction**(`theaction`: string | ActionCreator‹any›, `transform?`: undefined): *ActionCreator‹string, any›* - -**Parameters:** - -Name | Type | ------- | ------ | -`theaction` | string | ActionCreator‹any› | -`transform?` | undefined | - -**Returns:** *ActionCreator‹string, any›* - -___ - -### addEffect - -▸ **addEffect**<**AC**>(`creator`: AC, `middleware`: [UpduxMiddleware](../globals.md#upduxmiddleware)‹AggDuxState‹S, C›, [DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C›, ReturnType‹AC››, `isGenerator?`: undefined | false | true): *any* - -**Type parameters:** - -▪ **AC**: *ActionCreator* - -**Parameters:** - -Name | Type | ------- | ------ | -`creator` | AC | -`middleware` | [UpduxMiddleware](../globals.md#upduxmiddleware)‹AggDuxState‹S, C›, [DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C›, ReturnType‹AC›› | -`isGenerator?` | undefined | false | true | - -**Returns:** *any* - -▸ **addEffect**(`creator`: string, `middleware`: [UpduxMiddleware](../globals.md#upduxmiddleware)‹AggDuxState‹S, C›, [DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C››, `isGenerator?`: undefined | false | true): *any* - -**Parameters:** - -Name | Type | ------- | ------ | -`creator` | string | -`middleware` | [UpduxMiddleware](../globals.md#upduxmiddleware)‹AggDuxState‹S, C›, [DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C›› | -`isGenerator?` | undefined | false | true | - -**Returns:** *any* - -___ - -### addMutation - -▸ **addMutation**<**A**>(`creator`: A, `mutation`: [Mutation](../globals.md#mutation)‹S, ActionType‹A››, `isSink?`: undefined | false | true): *any* - -Adds a mutation and its associated action to the updux. - -**`remarks`** - -If a local mutation was already associated to the action, -it will be replaced by the new one. - -**`example`** - -```js -updux.addMutation( - action('ADD', payload() ), - inc => state => state + in -); -``` - -**Type parameters:** - -▪ **A**: *ActionCreator* - -**Parameters:** - -Name | Type | Description | ------- | ------ | ------ | -`creator` | A | - | -`mutation` | [Mutation](../globals.md#mutation)‹S, ActionType‹A›› | - | -`isSink?` | undefined | false | true | If `true`, disables the subduxes mutations for this action. To conditionally run the subduxes mutations, check out [subduxUpreducer](updux.md#subduxupreducer). Defaults to `false`. | - -**Returns:** *any* - -▸ **addMutation**<**A**>(`creator`: string, `mutation`: [Mutation](../globals.md#mutation)‹S, any›, `isSink?`: undefined | false | true): *any* - -**Type parameters:** - -▪ **A**: *ActionCreator* - -**Parameters:** - -Name | Type | ------- | ------ | -`creator` | string | -`mutation` | [Mutation](../globals.md#mutation)‹S, any› | -`isSink?` | undefined | false | true | - -**Returns:** *any* - -___ - -### addSelector - -▸ **addSelector**(`name`: string, `selector`: [Selector](../globals.md#selector)): *void* - -**Parameters:** - -Name | Type | ------- | ------ | -`name` | string | -`selector` | [Selector](../globals.md#selector) | - -**Returns:** *void* diff --git a/docs/API/globals.md b/docs/API/globals.md deleted file mode 100644 index cd61ed5..0000000 --- a/docs/API/globals.md +++ /dev/null @@ -1,980 +0,0 @@ -[updux - v1.2.0](README.md) › [Globals](globals.md) - -# updux - v1.2.0 - -## Index - -### Classes - -* [Updux](classes/updux.md) - -### Type aliases - -* [Action](globals.md#action) -* [ActionPair](globals.md#actionpair) -* [ActionPayloadGenerator](globals.md#actionpayloadgenerator) -* [ActionsOf](globals.md#actionsof) -* [CoduxesOf](globals.md#coduxesof) -* [Dictionary](globals.md#dictionary) -* [Dux](globals.md#dux) -* [DuxActions](globals.md#duxactions) -* [DuxActionsCoduxes](globals.md#duxactionscoduxes) -* [DuxActionsSubduxes](globals.md#duxactionssubduxes) -* [DuxSelectors](globals.md#duxselectors) -* [DuxState](globals.md#duxstate) -* [DuxStateCoduxes](globals.md#duxstatecoduxes) -* [DuxStateGlobSub](globals.md#duxstateglobsub) -* [DuxStateSubduxes](globals.md#duxstatesubduxes) -* [Effect](globals.md#effect) -* [GenericActions](globals.md#genericactions) -* [ItemsOf](globals.md#itemsof) -* [LocalDuxState](globals.md#localduxstate) -* [MaybePayload](globals.md#maybepayload) -* [MaybeReturnType](globals.md#maybereturntype) -* [Merge](globals.md#merge) -* [Mutation](globals.md#mutation) -* [MutationEntry](globals.md#mutationentry) -* [MwGen](globals.md#mwgen) -* [Next](globals.md#next) -* [RebaseSelector](globals.md#rebaseselector) -* [Selector](globals.md#selector) -* [SelectorsOf](globals.md#selectorsof) -* [StateOf](globals.md#stateof) -* [StoreWithDispatchActions](globals.md#storewithdispatchactions) -* [SubMutations](globals.md#submutations) -* [Submws](globals.md#submws) -* [UnionToIntersection](globals.md#uniontointersection) -* [UpduxActions](globals.md#upduxactions) -* [UpduxConfig](globals.md#upduxconfig) -* [UpduxLocalActions](globals.md#upduxlocalactions) -* [UpduxMiddleware](globals.md#upduxmiddleware) -* [Upreducer](globals.md#upreducer) - -### Variables - -* [subEffects](globals.md#const-subeffects) -* [updux](globals.md#const-updux) - -### Functions - -* [MiddlewareFor](globals.md#const-middlewarefor) -* [buildActions](globals.md#buildactions) -* [buildCreateStore](globals.md#buildcreatestore) -* [buildInitial](globals.md#buildinitial) -* [buildMiddleware](globals.md#buildmiddleware) -* [buildMutations](globals.md#buildmutations) -* [buildSelectors](globals.md#buildselectors) -* [buildUpreducer](globals.md#buildupreducer) -* [coduxes](globals.md#const-coduxes) -* [composeMutations](globals.md#const-composemutations) -* [composeMw](globals.md#const-composemw) -* [dux](globals.md#const-dux) -* [effectToMw](globals.md#const-effecttomw) -* [sliceMw](globals.md#slicemw) -* [subMiddleware](globals.md#const-submiddleware) -* [subSelectors](globals.md#subselectors) - -## Type aliases - -### Action - -Ƭ **Action**: *object & [MaybePayload](globals.md#maybepayload)‹P›* - -___ - -### ActionPair - -Ƭ **ActionPair**: *[string, ActionCreator]* - -___ - -### ActionPayloadGenerator - -Ƭ **ActionPayloadGenerator**: *function* - -#### Type declaration: - -▸ (...`args`: any[]): *any* - -**Parameters:** - -Name | Type | ------- | ------ | -`...args` | any[] | - -___ - -### ActionsOf - -Ƭ **ActionsOf**: *U extends Updux ? U["actions"] : object* - -___ - -### CoduxesOf - -Ƭ **CoduxesOf**: *U extends Updux ? S : []* - -___ - -### Dictionary - -Ƭ **Dictionary**: *object* - -#### Type declaration: - -* \[ **key**: *string*\]: T - -___ - -### Dux - -Ƭ **Dux**: *object* - -#### Type declaration: - -* **actions**: *A* - -* **coduxes**: *[Dux](globals.md#dux)[]* - -* **initial**: *AggDuxState‹S, C›* - -* **subduxes**: *[Dictionary](globals.md#dictionary)‹[Dux](globals.md#dux)›* - -___ - -### DuxActions - -Ƭ **DuxActions**: - -___ - -### DuxActionsCoduxes - -Ƭ **DuxActionsCoduxes**: *C extends Array ? UnionToIntersection> : object* - -___ - -### DuxActionsSubduxes - -Ƭ **DuxActionsSubduxes**: *C extends object ? ActionsOf : unknown* - -___ - -### DuxSelectors - -Ƭ **DuxSelectors**: *unknown extends X ? object : X* - -___ - -### DuxState - -Ƭ **DuxState**: *D extends object ? S : unknown* - -___ - -### DuxStateCoduxes - -Ƭ **DuxStateCoduxes**: *C extends Array ? UnionToIntersection> : unknown* - -___ - -### DuxStateGlobSub - -Ƭ **DuxStateGlobSub**: *S extends object ? StateOf : unknown* - -___ - -### DuxStateSubduxes - -Ƭ **DuxStateSubduxes**: *C extends object ? object : C extends object ? object : unknown* - -___ - -### Effect - -Ƭ **Effect**: *[string, [UpduxMiddleware](globals.md#upduxmiddleware) | [MwGen](globals.md#mwgen), undefined | false | true]* - -___ - -### GenericActions - -Ƭ **GenericActions**: *[Dictionary](globals.md#dictionary)‹ActionCreator‹string, function››* - -___ - -### ItemsOf - -Ƭ **ItemsOf**: *C extends object ? C[keyof C] : unknown* - -___ - -### LocalDuxState - -Ƭ **LocalDuxState**: *S extends never[] ? unknown[] : S* - -___ - -### MaybePayload - -Ƭ **MaybePayload**: *P extends object | string | boolean | number ? object : object* - -___ - -### MaybeReturnType - -Ƭ **MaybeReturnType**: *X extends function ? ReturnType : unknown* - -___ - -### Merge - -Ƭ **Merge**: *[UnionToIntersection](globals.md#uniontointersection)‹T[keyof T]›* - -___ - -### Mutation - -Ƭ **Mutation**: *function* - -#### Type declaration: - -▸ (`payload`: A["payload"], `action`: A): *function* - -**Parameters:** - -Name | Type | ------- | ------ | -`payload` | A["payload"] | -`action` | A | - -▸ (`state`: S): *S* - -**Parameters:** - -Name | Type | ------- | ------ | -`state` | S | - -___ - -### MutationEntry - -Ƭ **MutationEntry**: *[ActionCreator | string, [Mutation](globals.md#mutation)‹any, [Action](globals.md#action)‹string, any››, undefined | false | true]* - -___ - -### MwGen - -Ƭ **MwGen**: *function* - -#### Type declaration: - -▸ (): *[UpduxMiddleware](globals.md#upduxmiddleware)* - -___ - -### Next - -Ƭ **Next**: *function* - -#### Type declaration: - -▸ (`action`: [Action](globals.md#action)): *any* - -**Parameters:** - -Name | Type | ------- | ------ | -`action` | [Action](globals.md#action) | - -___ - -### RebaseSelector - -Ƭ **RebaseSelector**: *object* - -#### Type declaration: - -___ - -### Selector - -Ƭ **Selector**: *function* - -#### Type declaration: - -▸ (`state`: S): *unknown* - -**Parameters:** - -Name | Type | ------- | ------ | -`state` | S | - -___ - -### SelectorsOf - -Ƭ **SelectorsOf**: *C extends object ? S : unknown* - -___ - -### StateOf - -Ƭ **StateOf**: *D extends object ? I : unknown* - -___ - -### StoreWithDispatchActions - -Ƭ **StoreWithDispatchActions**: *Store‹S› & object* - -___ - -### SubMutations - -Ƭ **SubMutations**: *object* - -#### Type declaration: - -* \[ **slice**: *string*\]: [Dictionary](globals.md#dictionary)‹[Mutation](globals.md#mutation)› - -___ - -### Submws - -Ƭ **Submws**: *[Dictionary](globals.md#dictionary)‹[UpduxMiddleware](globals.md#upduxmiddleware)›* - -___ - -### UnionToIntersection - -Ƭ **UnionToIntersection**: *U extends any ? function : never extends function ? I : never* - -___ - -### UpduxActions - -Ƭ **UpduxActions**: *U extends Updux ? UnionToIntersection | ActionsOf[keyof CoduxesOf]>> : object* - -___ - -### UpduxConfig - -Ƭ **UpduxConfig**: *Partial‹object›* - -Configuration object given to Updux's constructor. - -#### arguments - -##### initial - -Default initial state of the reducer. If applicable, is merged with -the subduxes initial states, with the parent having precedence. - -If not provided, defaults to an empty object. - -##### actions - -[Actions](/concepts/Actions) used by the updux. - -```js -import { dux } from 'updux'; -import { action, payload } from 'ts-action'; - -const bar = action('BAR', payload()); -const foo = action('FOO'); - -const myDux = dux({ - actions: { - bar - }, - mutations: [ - [ foo, () => state => state ] - ] -}); - -myDux.actions.foo({ x: 1, y: 2 }); // => { type: foo, x:1, y:2 } -myDux.actions.bar(2); // => { type: bar, payload: 2 } -``` - -New actions used directly in mutations and effects will be added to the -dux actions -- that is, they will be accessible via `dux.actions` -- but will -not appear as part of its Typescript type. - -##### selectors - -Dictionary of selectors for the current updux. The updux also -inherit its subduxes' selectors. - -The selectors are available via the class' getter. - -##### mutations - - mutations: [ - [ action, mutation, isSink ], - ... - ] - -or - - mutations: { - action: mutation, - ... - } - -List of mutations for assign to the dux. If you want Typescript goodness, you -probably want to use `addMutation()` instead. - -In its generic array-of-array form, -each mutation tuple contains: the action, the mutation, -and boolean indicating if this is a sink mutation. - -The action can be an action creator function or a string. If it's a string, it's considered to be the -action type and a generic `action( actionName, payload() )` creator will be -generated for it. If an action is not already defined in the `actions` -parameter, it'll be automatically added. - -The pseudo-action type `*` can be used to match any action not explicitly matched by other mutations. - -```js -const todosUpdux = updux({ - mutations: { - add: todo => state => [ ...state, todo ], - done: done_id => u.map( u.if( ({id} => id === done_id), {done: true} ) ), - '*' (payload,action) => state => { - console.warn( "unexpected action ", action.type ); - return state; - }, - } -}); -``` - -The signature of the mutations is `(payload,action) => state => newState`. -It is designed to play well with `Updeep` (and [Immer](https://immerjs.github.io/immer/docs/introduction)). This way, instead of doing - -```js - mutation: { - renameTodo: newName => state => { ...state, name: newName } - } -``` - -we can do - -```js - mutation: { - renameTodo: newName => u({ name: newName }) - } -``` - -The final argument is the optional boolean `isSink`. If it is true, it'll -prevent subduxes' mutations on the same action. It defaults to `false`. - -The object version of the argument can be used as a shortcut when all actions -are strings. In that case, `isSink` is `false` for all mutations. - -##### groomMutations - -Function that can be provided to alter all local mutations of the updux -(the mutations of subduxes are left untouched). - -Can be used, for example, for Immer integration: - -```js -import Updux from 'updux'; -import { produce } from 'Immer'; - -const updux = new Updux({ - initial: { counter: 0 }, - groomMutations: mutation => (...args) => produce( mutation(...args) ), - mutations: { - add: (inc=1) => draft => draft.counter += inc - } -}); -``` - -Or perhaps for debugging: - -```js -import Updux from 'updux'; - -const updux = new Updux({ - initial: { counter: 0 }, - groomMutations: mutation => (...args) => state => { - console.log( "got action ", args[1] ); - return mutation(...args)(state); - } -}); -``` -##### subduxes - -Object mapping slices of the state to sub-upduxes. In addition to creating -sub-reducers for those slices, it'll make the parend updux inherit all the -actions and middleware from its subduxes. - -For example, if in plain Redux you would do - -```js -import { combineReducers } from 'redux'; -import todosReducer from './todos'; -import statisticsReducer from './statistics'; - -const rootReducer = combineReducers({ - todos: todosReducer, - stats: statisticsReducer, -}); -``` - -then with Updux you'd do - -```js -import { updux } from 'updux'; -import todos from './todos'; -import statistics from './statistics'; - -const rootUpdux = updux({ - subduxes: { - todos, - statistics - } -}); -``` - -##### effects - -Array of arrays or plain object defining asynchronous actions and side-effects triggered by actions. -The effects themselves are Redux middleware, with the `dispatch` -property of the first argument augmented with all the available actions. - -``` -updux({ - effects: { - fetch: ({dispatch}) => next => async (action) => { - next(action); - - let result = await fetch(action.payload.url).then( result => result.json() ); - dispatch.fetchSuccess(result); - } - } -}); -``` - -**`example`** - -``` -import Updux from 'updux'; -import { actions, payload } from 'ts-action'; -import u from 'updeep'; - -const todoUpdux = new Updux({ - initial: { - done: false, - note: "", - }, - actions: { - finish: action('FINISH', payload()), - edit: action('EDIT', payload()), - }, - mutations: [ - [ edit, note => u({note}) ] - ], - selectors: { - getNote: state => state.note - }, - groomMutations: mutation => transform(mutation), - subduxes: { - foo - }, - effects: { - finish: () => next => action => { - console.log( "Woo! one more bites the dust" ); - } - } -}) -``` - -___ - -### UpduxLocalActions - -Ƭ **UpduxLocalActions**: *S extends Updux ? object : S extends Updux ? A : object* - -___ - -### UpduxMiddleware - -Ƭ **UpduxMiddleware**: *function* - -#### Type declaration: - -▸ (`api`: UpduxMiddlewareAPI‹S, X›): *function* - -**Parameters:** - -Name | Type | ------- | ------ | -`api` | UpduxMiddlewareAPI‹S, X› | - -▸ (`next`: Function): *function* - -**Parameters:** - -Name | Type | ------- | ------ | -`next` | Function | - -▸ (`action`: A): *any* - -**Parameters:** - -Name | Type | ------- | ------ | -`action` | A | - -___ - -### Upreducer - -Ƭ **Upreducer**: *function* - -#### Type declaration: - -▸ (`action`: [Action](globals.md#action)): *function* - -**Parameters:** - -Name | Type | ------- | ------ | -`action` | [Action](globals.md#action) | - -▸ (`state`: S): *S* - -**Parameters:** - -Name | Type | ------- | ------ | -`state` | S | - -## Variables - -### `Const` subEffects - -• **subEffects**: *[Effect](globals.md#effect)* = [ '*', subMiddleware ] as any - -___ - -### `Const` updux - -• **updux**: *[Updux](classes/updux.md)‹unknown, null, unknown, object›* = new Updux({ - subduxes: { - foo: dux({ initial: "banana" }) - } -}) - -## Functions - -### `Const` MiddlewareFor - -▸ **MiddlewareFor**(`type`: any, `mw`: Middleware): *Middleware* - -**Parameters:** - -Name | Type | ------- | ------ | -`type` | any | -`mw` | Middleware | - -**Returns:** *Middleware* - -___ - -### buildActions - -▸ **buildActions**(`actions`: [ActionPair](globals.md#actionpair)[]): *[Dictionary](globals.md#dictionary)‹ActionCreator‹string, function››* - -**Parameters:** - -Name | Type | Default | ------- | ------ | ------ | -`actions` | [ActionPair](globals.md#actionpair)[] | [] | - -**Returns:** *[Dictionary](globals.md#dictionary)‹ActionCreator‹string, function››* - -___ - -### buildCreateStore - -▸ **buildCreateStore**<**S**, **A**>(`reducer`: Reducer‹S›, `middleware`: Middleware, `actions`: A): *function* - -**Type parameters:** - -▪ **S** - -▪ **A** - -**Parameters:** - -Name | Type | Default | ------- | ------ | ------ | -`reducer` | Reducer‹S› | - | -`middleware` | Middleware | - | -`actions` | A | {} as A | - -**Returns:** *function* - -▸ (`initial?`: S, `injectEnhancer?`: Function): *Store‹S› & object* - -**Parameters:** - -Name | Type | ------- | ------ | -`initial?` | S | -`injectEnhancer?` | Function | - -___ - -### buildInitial - -▸ **buildInitial**(`initial`: any, `coduxes`: any, `subduxes`: any): *any* - -**Parameters:** - -Name | Type | Default | ------- | ------ | ------ | -`initial` | any | - | -`coduxes` | any | [] | -`subduxes` | any | {} | - -**Returns:** *any* - -___ - -### buildMiddleware - -▸ **buildMiddleware**<**S**>(`local`: [UpduxMiddleware](globals.md#upduxmiddleware)[], `co`: [UpduxMiddleware](globals.md#upduxmiddleware)[], `sub`: [Submws](globals.md#submws)): *[UpduxMiddleware](globals.md#upduxmiddleware)‹S›* - -**Type parameters:** - -▪ **S** - -**Parameters:** - -Name | Type | Default | ------- | ------ | ------ | -`local` | [UpduxMiddleware](globals.md#upduxmiddleware)[] | [] | -`co` | [UpduxMiddleware](globals.md#upduxmiddleware)[] | [] | -`sub` | [Submws](globals.md#submws) | {} | - -**Returns:** *[UpduxMiddleware](globals.md#upduxmiddleware)‹S›* - -___ - -### buildMutations - -▸ **buildMutations**(`mutations`: [Dictionary](globals.md#dictionary)‹[Mutation](globals.md#mutation) | [[Mutation](globals.md#mutation), boolean | undefined]›, `subduxes`: object, `coduxes`: [Upreducer](globals.md#upreducer)[]): *object* - -**Parameters:** - -Name | Type | Default | ------- | ------ | ------ | -`mutations` | [Dictionary](globals.md#dictionary)‹[Mutation](globals.md#mutation) | [[Mutation](globals.md#mutation), boolean | undefined]› | {} | -`subduxes` | object | {} | -`coduxes` | [Upreducer](globals.md#upreducer)[] | [] | - -**Returns:** *object* - -___ - -### buildSelectors - -▸ **buildSelectors**(`localSelectors`: [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)›, `coduxes`: [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)›[], `subduxes`: [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)›): *object* - -**Parameters:** - -Name | Type | Default | ------- | ------ | ------ | -`localSelectors` | [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)› | {} | -`coduxes` | [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)›[] | [] | -`subduxes` | [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)› | {} | - -**Returns:** *object* - -___ - -### buildUpreducer - -▸ **buildUpreducer**<**S**>(`initial`: S, `mutations`: [Dictionary](globals.md#dictionary)‹[Mutation](globals.md#mutation)‹S››): *[Upreducer](globals.md#upreducer)‹S›* - -**Type parameters:** - -▪ **S** - -**Parameters:** - -Name | Type | ------- | ------ | -`initial` | S | -`mutations` | [Dictionary](globals.md#dictionary)‹[Mutation](globals.md#mutation)‹S›› | - -**Returns:** *[Upreducer](globals.md#upreducer)‹S›* - -___ - -### `Const` coduxes - -▸ **coduxes**<**C**, **U**>(...`coduxes`: U): *object* - -**Type parameters:** - -▪ **C**: *[Dux](globals.md#dux)* - -▪ **U**: *[C]* - -**Parameters:** - -Name | Type | ------- | ------ | -`...coduxes` | U | - -**Returns:** *object* - -* **coduxes**: *U* - -___ - -### `Const` composeMutations - -▸ **composeMutations**(`mutations`: [Mutation](globals.md#mutation)[]): *function | (Anonymous function)* - -**Parameters:** - -Name | Type | ------- | ------ | -`mutations` | [Mutation](globals.md#mutation)[] | - -**Returns:** *function | (Anonymous function)* - -___ - -### `Const` composeMw - -▸ **composeMw**(`mws`: [UpduxMiddleware](globals.md#upduxmiddleware)[]): *(Anonymous function)* - -**Parameters:** - -Name | Type | ------- | ------ | -`mws` | [UpduxMiddleware](globals.md#upduxmiddleware)[] | - -**Returns:** *(Anonymous function)* - -___ - -### `Const` dux - -▸ **dux**<**S**, **A**, **X**, **C**>(`config`: C): *object* - -**Type parameters:** - -▪ **S** - -▪ **A** - -▪ **X** - -▪ **C**: *[UpduxConfig](globals.md#upduxconfig)* - -**Parameters:** - -Name | Type | ------- | ------ | -`config` | C | - -**Returns:** *object* - -* **actions**: = this.actions - -* **coduxes**: *object[]* = this.coduxes - -* **createStore**(): *function* - - * (`initial?`: S, `injectEnhancer?`: Function): *Store‹S› & object* - -* **initial**: = this.initial - -* **middleware**(): *function* - - * (`api`: UpduxMiddlewareAPI‹S, X›): *function* - - * (`next`: Function): *function* - - * (`action`: A): *any* - -* **mutations**(): *object* - -* **reducer**(): *function* - - * (`state`: S | undefined, `action`: [Action](globals.md#action)): *S* - -* **selectors**: = this.selectors - -* **subduxes**(): *object* - -* **upreducer**(): *function* - - * (`action`: [Action](globals.md#action)): *function* - - * (`state`: S): *S* - -___ - -### `Const` effectToMw - -▸ **effectToMw**(`effect`: [Effect](globals.md#effect), `actions`: [Dictionary](globals.md#dictionary)‹ActionCreator›, `selectors`: [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)›): *subMiddleware | augmented* - -**Parameters:** - -Name | Type | ------- | ------ | -`effect` | [Effect](globals.md#effect) | -`actions` | [Dictionary](globals.md#dictionary)‹ActionCreator› | -`selectors` | [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)› | - -**Returns:** *subMiddleware | augmented* - -___ - -### sliceMw - -▸ **sliceMw**(`slice`: string, `mw`: [UpduxMiddleware](globals.md#upduxmiddleware)): *[UpduxMiddleware](globals.md#upduxmiddleware)* - -**Parameters:** - -Name | Type | ------- | ------ | -`slice` | string | -`mw` | [UpduxMiddleware](globals.md#upduxmiddleware) | - -**Returns:** *[UpduxMiddleware](globals.md#upduxmiddleware)* - -___ - -### `Const` subMiddleware - -▸ **subMiddleware**(): *(Anonymous function)* - -**Returns:** *(Anonymous function)* - -___ - -### subSelectors - -▸ **subSelectors**(`__namedParameters`: [string, Function]): *[string, [Selector](globals.md#selector)][]* - -**Parameters:** - -Name | Type | ------- | ------ | -`__namedParameters` | [string, Function] | - -**Returns:** *[string, [Selector](globals.md#selector)][]* diff --git a/tsdocs/index.html b/docs/API/index.html similarity index 95% rename from tsdocs/index.html rename to docs/API/index.html index ebcc90c..be83de2 100644 --- a/tsdocs/index.html +++ b/docs/API/index.html @@ -1,4 +1,4 @@ -updux
Options
All
  • Public
  • Public/Protected
  • All
Menu

updux

+Updux
Options
All
  • Public
  • Public/Protected
  • All
Menu

Updux

What's Updux?

@@ -89,4 +89,4 @@ well with Immer. can be used to wrap all mutations with it:

import Updux from 'updux';
import { produce } from 'Immer';

const updux = new Updux({
initial: { counter: 0 },
groomMutations: mutation => (...args) => produce( mutation(...args) ),
mutations: {
add: (inc=1) => draft => draft.counter += inc
}
});
-

Settings

Theme

Generated using TypeDoc

\ No newline at end of file +

Settings

Theme

Generated using TypeDoc

\ No newline at end of file diff --git a/docs/API/interfaces/_updux_.UpduxConfig.html b/docs/API/interfaces/_updux_.UpduxConfig.html new file mode 100644 index 0000000..0ebc9ec --- /dev/null +++ b/docs/API/interfaces/_updux_.UpduxConfig.html @@ -0,0 +1,25 @@ +UpduxConfig | Updux
Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface UpduxConfig<TState>

+

Configuration object typically passed to the constructor of the class Updux.

+

Type parameters

  • TState = unknown

Hierarchy

  • UpduxConfig

Index

Properties

Optional actions

actions?: Record<string, any>
+

Local actions.

+

Optional effects

effects?: Record<string, Function>
+

Local effects.

+

Optional initial

initial?: TState
+

Local initial state.

+
default

{}

+

Optional mappedReaction

mappedReaction?: boolean | Function
+

If true, enables mapped reactions. Additionally, it can be +a reaction function, which will treated as a regular +reaction for the mapped dux.

+

Optional mappedSelectors

mappedSelectors?: Record<string, Function>
+

Selectors to apply to the mapped subduxes. Only + applicable if the dux is a mapping dux.

+

Optional mutations

mutations?: Record<string, Function>
+

Local mutations

+

Optional reactions

reactions?: Record<string, Function>
+

Local reactions.

+

Optional selectors

selectors?: Record<string, Function>
+

Local selectors.

+

Optional subduxes

subduxes?: Dict<Updux<unknown> | UpduxConfig<unknown>>
+

Subduxes to be merged to this dux.

+

Legend

  • Property

Settings

Theme

Generated using TypeDoc

\ No newline at end of file diff --git a/docs/API/modules.html b/docs/API/modules.html new file mode 100644 index 0000000..9ac765d --- /dev/null +++ b/docs/API/modules.html @@ -0,0 +1 @@ +Updux
Options
All
  • Public
  • Public/Protected
  • All
Menu

Updux

Index

Namespaces

Type aliases

Type aliases

Dict

Dict<T>: Record<string, T>

Type parameters

  • T

Settings

Theme

Generated using TypeDoc

\ No newline at end of file diff --git a/docs/API/modules/_updux_.html b/docs/API/modules/_updux_.html new file mode 100644 index 0000000..75318cb --- /dev/null +++ b/docs/API/modules/_updux_.html @@ -0,0 +1 @@ +"updux" | Updux
Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace "updux"

Settings

Theme

Generated using TypeDoc

\ No newline at end of file diff --git a/docs/index.html b/docs/index.html index eefd702..dcfdc00 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,128 +1,24 @@ - - - - - - - - Home - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - -
-
-
- -
-
-
-

-

Home

-
- - - - - - - -

- - - - - - - - - - - - - - - - - - - - -
- - - -
-
-
-
- - - - - - \ No newline at end of file + + + + + updux - Updeep-friendly Redux helper framework + + + + + + +
+ + + + diff --git a/pagesconfig.json b/pagesconfig.json new file mode 100644 index 0000000..8ba1efe --- /dev/null +++ b/pagesconfig.json @@ -0,0 +1,13 @@ +{ + "groups": [ + { + "title": "Documentation", + "pages": [ + { + "title": "Blah", + "source": "./tutorials/tutorial.md" + } + ] + } + ] +} diff --git a/src/Updux.d.ts b/src/Updux.d.ts new file mode 100644 index 0000000..8e0af6f --- /dev/null +++ b/src/Updux.d.ts @@ -0,0 +1,20 @@ +type UpduxConfig = Partial<{ + initial: TState; + subduxes: Record; + actions: Record; + selectors: Record; + mutations: Record; + mappedSelectors: Record; + effects: Record; + reactions: Record; + mappedReaction: Function; +}> + + +export class Updux { + + constructor( config: UpduxConfig ); + + get initial(): TState; + get selectors(): unknown; +} diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..25a85a1 --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1 @@ +export { Updux }; diff --git a/tsconfig.json b/tsconfig.json index 4152345..a22e7a1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,26 +1,27 @@ { + "include": ["./types/*.d.ts"], "exclude": [ "types/index.test-d.ts" ], "compilerOptions": { /* Visit https://aka.ms/tsconfig.json to read more about this file */ /* Basic Options */ - // "incremental": true, /* Enable incremental compilation */ + "incremental": false, /* Enable incremental compilation */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', 'ES2021', or 'ESNEXT'. */ "module": "ESNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation. */ - // "allowJs": true, /* Allow javascript files to be compiled. */ + "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */ - // "declaration": true, /* Generates corresponding '.d.ts' file. */ + "declaration": true, /* Generates corresponding '.d.ts' file. */ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ - // "outDir": "./", /* Redirect output structure to the directory. */ + "outDir": "./ts-out", /* Redirect output structure to the directory. */ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ // "removeComments": true, /* Do not emit comments to output. */ - // "noEmit": true, /* Do not emit outputs. */ + "noEmit": true, /* Do not emit outputs. */ // "importHelpers": true, /* Import emit helpers from 'tslib'. */ // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ @@ -48,8 +49,8 @@ "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ - // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ - // "typeRoots": [], /* List of folders to include type definitions from. */ + "rootDirs": ["./types"], /* List of root folders whose combined content represents the structure of the project at runtime. */ + "typeRoots": ["./types"], /* List of folders to include type definitions from. */ // "types": [], /* Type declaration files to be included in compilation. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ diff --git a/tsdocs/assets/search.js b/tsdocs/assets/search.js deleted file mode 100644 index d94ce50..0000000 --- a/tsdocs/assets/search.js +++ /dev/null @@ -1 +0,0 @@ -window.searchData = {"kinds":{},"rows":[],"index":{"version":"2.3.9","fields":["name","parent"],"fieldVectors":[],"invertedIndex":[],"pipeline":[]}} \ No newline at end of file diff --git a/tsdocs/modules.html b/tsdocs/modules.html deleted file mode 100644 index fd4cc9c..0000000 --- a/tsdocs/modules.html +++ /dev/null @@ -1 +0,0 @@ -updux
Options
All
  • Public
  • Public/Protected
  • All
Menu

updux

Settings

Theme

Generated using TypeDoc

\ No newline at end of file diff --git a/typedoc.json b/typedoc.json new file mode 100644 index 0000000..91a2cf5 --- /dev/null +++ b/typedoc.json @@ -0,0 +1,15 @@ +{ + "name": "Updux", + "entryPoints": [ + "./types/index.d.ts" + ], + "out": "docs/API", + "excludeExternals": true, + "excludePrivate": true, + "excludeProtected": true, + "disableSources": true, + "listInvalidSymbolLinks": true, + "markedOptions": { + "mangle": false + } +} diff --git a/types/index.d.ts b/types/index.d.ts index 8e0af6f..9acd963 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,20 +1,63 @@ -type UpduxConfig = Partial<{ - initial: TState; - subduxes: Record; - actions: Record; - selectors: Record; - mutations: Record; - mappedSelectors: Record; - effects: Record; - reactions: Record; - mappedReaction: Function; -}> +type Dict = Record; +declare module 'updux' { + /** + * Configuration object typically passed to the constructor of the class Updux. + */ + export interface UpduxConfig { + /** + * Local initial state. + * @default {} + */ + initial?: TState; -export class Updux { + /** + * Subduxes to be merged to this dux. + */ + subduxes?: Dict; - constructor( config: UpduxConfig ); + /** + * Local actions. + */ + actions?: Record; - get initial(): TState; - get selectors(): unknown; + /** + * Local selectors. + */ + selectors?: Record; + + /** + * Local mutations + */ + mutations?: Record; + + /** + * Selectors to apply to the mapped subduxes. Only + * applicable if the dux is a mapping dux. + */ + mappedSelectors?: Record; + + /** + * Local effects. + */ + effects?: Record; + + /** + * Local reactions. + */ + reactions?: Record; + /** + * If true, enables mapped reactions. Additionally, it can be + * a reaction function, which will treated as a regular + * reaction for the mapped dux. + */ + mappedReaction?: Function | boolean; + } + + export class Updux { + constructor(config: Partial>); + + get initial(): TState; + get selectors(): unknown; + } }