From 6dd8b1af9ed300c37ecfff883cf638a5106f738c Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Wed, 13 Oct 2021 13:54:17 -0400 Subject: [PATCH] rename leftover from * to + --- docs/API/assets/search.js | 2 +- docs/API/modules/_updux_.html | 4 +- docs/concepts.md | 63 +++++++++++++-- docs/tutorial.md | 140 +++++----------------------------- src/Updux.js | 2 +- src/buildUpreducer.js | 2 +- src/documentation.test.js | 2 + src/index.js | 2 +- src/mutations.test.js | 2 +- types/index.d.ts | 8 ++ 10 files changed, 93 insertions(+), 134 deletions(-) diff --git a/docs/API/assets/search.js b/docs/API/assets/search.js index 02b53f8..1adfcf9 100644 --- a/docs/API/assets/search.js +++ b/docs/API/assets/search.js @@ -1 +1 @@ -window.searchData = {"kinds":{"4":"Namespace","128":"Class","256":"Interface","512":"Constructor","1024":"Property","2048":"Method","65536":"Type literal","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":4194304,"name":"Mutation","url":"modules.html#Mutation","classes":"tsd-kind-type-alias tsd-has-type-parameter"},{"id":2,"kind":65536,"name":"__type","url":"modules.html#Mutation.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias","parent":"Mutation"},{"id":3,"kind":4194304,"name":"ActionGenerator","url":"modules.html#ActionGenerator","classes":"tsd-kind-type-alias"},{"id":4,"kind":4,"name":"\"updux\"","url":"modules/_updux_.html","classes":"tsd-kind-namespace"},{"id":5,"kind":256,"name":"UpduxConfig","url":"interfaces/_updux_.UpduxConfig.html","classes":"tsd-kind-interface tsd-parent-kind-namespace tsd-has-type-parameter","parent":"\"updux\""},{"id":6,"kind":1024,"name":"initial","url":"interfaces/_updux_.UpduxConfig.html#initial","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":7,"kind":1024,"name":"subduxes","url":"interfaces/_updux_.UpduxConfig.html#subduxes","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":8,"kind":1024,"name":"actions","url":"interfaces/_updux_.UpduxConfig.html#actions","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":9,"kind":1024,"name":"selectors","url":"interfaces/_updux_.UpduxConfig.html#selectors","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":10,"kind":1024,"name":"mutations","url":"interfaces/_updux_.UpduxConfig.html#mutations","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":11,"kind":1024,"name":"mappedSelectors","url":"interfaces/_updux_.UpduxConfig.html#mappedSelectors","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":12,"kind":1024,"name":"effects","url":"interfaces/_updux_.UpduxConfig.html#effects","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":13,"kind":1024,"name":"reactions","url":"interfaces/_updux_.UpduxConfig.html#reactions","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":14,"kind":1024,"name":"mappedReaction","url":"interfaces/_updux_.UpduxConfig.html#mappedReaction","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":15,"kind":128,"name":"Updux","url":"classes/_updux_.Updux.html","classes":"tsd-kind-class tsd-parent-kind-namespace tsd-has-type-parameter","parent":"\"updux\""},{"id":16,"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":17,"kind":262144,"name":"initial","url":"classes/_updux_.Updux.html#initial","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"\"updux\".Updux"},{"id":18,"kind":262144,"name":"selectors","url":"classes/_updux_.Updux.html#selectors","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"\"updux\".Updux"},{"id":19,"kind":2048,"name":"setMutation","url":"classes/_updux_.Updux.html#setMutation","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter","parent":"\"updux\".Updux"},{"id":20,"kind":2048,"name":"setAction","url":"classes/_updux_.Updux.html#setAction","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"updux\".Updux"}],"index":{"version":"2.3.9","fields":["name","parent"],"fieldVectors":[["name/0",[0,26.856]],["parent/0",[]],["name/1",[1,21.748]],["parent/1",[]],["name/2",[2,26.856]],["parent/2",[1,1.984]],["name/3",[3,26.856]],["parent/3",[]],["name/4",[4,15.87]],["parent/4",[]],["name/5",[5,26.856]],["parent/5",[4,1.448]],["name/6",[6,21.748]],["parent/6",[7,0.766]],["name/7",[8,26.856]],["parent/7",[7,0.766]],["name/8",[9,26.856]],["parent/8",[7,0.766]],["name/9",[10,21.748]],["parent/9",[7,0.766]],["name/10",[11,26.856]],["parent/10",[7,0.766]],["name/11",[12,26.856]],["parent/11",[7,0.766]],["name/12",[13,26.856]],["parent/12",[7,0.766]],["name/13",[14,26.856]],["parent/13",[7,0.766]],["name/14",[15,26.856]],["parent/14",[7,0.766]],["name/15",[4,15.87]],["parent/15",[4,1.448]],["name/16",[16,26.856]],["parent/16",[17,1.265]],["name/17",[6,21.748]],["parent/17",[17,1.265]],["name/18",[10,21.748]],["parent/18",[17,1.265]],["name/19",[18,26.856]],["parent/19",[17,1.265]],["name/20",[19,26.856]],["parent/20",[17,1.265]]],"invertedIndex":[["__type",{"_index":2,"name":{"2":{}},"parent":{}}],["actiongenerator",{"_index":3,"name":{"3":{}},"parent":{}}],["actions",{"_index":9,"name":{"8":{}},"parent":{}}],["constructor",{"_index":16,"name":{"16":{}},"parent":{}}],["dict",{"_index":0,"name":{"0":{}},"parent":{}}],["effects",{"_index":13,"name":{"12":{}},"parent":{}}],["initial",{"_index":6,"name":{"6":{},"17":{}},"parent":{}}],["mappedreaction",{"_index":15,"name":{"14":{}},"parent":{}}],["mappedselectors",{"_index":12,"name":{"11":{}},"parent":{}}],["mutation",{"_index":1,"name":{"1":{}},"parent":{"2":{}}}],["mutations",{"_index":11,"name":{"10":{}},"parent":{}}],["reactions",{"_index":14,"name":{"13":{}},"parent":{}}],["selectors",{"_index":10,"name":{"9":{},"18":{}},"parent":{}}],["setaction",{"_index":19,"name":{"20":{}},"parent":{}}],["setmutation",{"_index":18,"name":{"19":{}},"parent":{}}],["subduxes",{"_index":8,"name":{"7":{}},"parent":{}}],["updux",{"_index":4,"name":{"4":{},"15":{}},"parent":{"5":{},"15":{}}}],["updux\".updux",{"_index":17,"name":{},"parent":{"16":{},"17":{},"18":{},"19":{},"20":{}}}],["updux\".upduxconfig",{"_index":7,"name":{},"parent":{"6":{},"7":{},"8":{},"9":{},"10":{},"11":{},"12":{},"13":{},"14":{}}}],["upduxconfig",{"_index":5,"name":{"5":{}},"parent":{}}]],"pipeline":[]}} \ No newline at end of file +window.searchData = {"kinds":{"4":"Namespace","64":"Function","128":"Class","256":"Interface","512":"Constructor","1024":"Property","2048":"Method","65536":"Type literal","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":4194304,"name":"Mutation","url":"modules.html#Mutation","classes":"tsd-kind-type-alias tsd-has-type-parameter"},{"id":2,"kind":65536,"name":"__type","url":"modules.html#Mutation.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias","parent":"Mutation"},{"id":3,"kind":4194304,"name":"ActionGenerator","url":"modules.html#ActionGenerator","classes":"tsd-kind-type-alias"},{"id":4,"kind":4,"name":"\"updux\"","url":"modules/_updux_.html","classes":"tsd-kind-namespace"},{"id":5,"kind":64,"name":"action","url":"modules/_updux_.html#action","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"\"updux\""},{"id":6,"kind":256,"name":"UpduxConfig","url":"interfaces/_updux_.UpduxConfig.html","classes":"tsd-kind-interface tsd-parent-kind-namespace tsd-has-type-parameter","parent":"\"updux\""},{"id":7,"kind":1024,"name":"initial","url":"interfaces/_updux_.UpduxConfig.html#initial","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":8,"kind":1024,"name":"subduxes","url":"interfaces/_updux_.UpduxConfig.html#subduxes","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":9,"kind":1024,"name":"actions","url":"interfaces/_updux_.UpduxConfig.html#actions","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":10,"kind":1024,"name":"selectors","url":"interfaces/_updux_.UpduxConfig.html#selectors","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":11,"kind":1024,"name":"mutations","url":"interfaces/_updux_.UpduxConfig.html#mutations","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":12,"kind":1024,"name":"mappedSelectors","url":"interfaces/_updux_.UpduxConfig.html#mappedSelectors","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":13,"kind":1024,"name":"effects","url":"interfaces/_updux_.UpduxConfig.html#effects","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":14,"kind":1024,"name":"reactions","url":"interfaces/_updux_.UpduxConfig.html#reactions","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":15,"kind":1024,"name":"mappedReaction","url":"interfaces/_updux_.UpduxConfig.html#mappedReaction","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"\"updux\".UpduxConfig"},{"id":16,"kind":128,"name":"Updux","url":"classes/_updux_.Updux.html","classes":"tsd-kind-class tsd-parent-kind-namespace tsd-has-type-parameter","parent":"\"updux\""},{"id":17,"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":18,"kind":262144,"name":"initial","url":"classes/_updux_.Updux.html#initial","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"\"updux\".Updux"},{"id":19,"kind":262144,"name":"selectors","url":"classes/_updux_.Updux.html#selectors","classes":"tsd-kind-get-signature tsd-parent-kind-class","parent":"\"updux\".Updux"},{"id":20,"kind":2048,"name":"setMutation","url":"classes/_updux_.Updux.html#setMutation","classes":"tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter","parent":"\"updux\".Updux"},{"id":21,"kind":2048,"name":"setAction","url":"classes/_updux_.Updux.html#setAction","classes":"tsd-kind-method tsd-parent-kind-class","parent":"\"updux\".Updux"}],"index":{"version":"2.3.9","fields":["name","parent"],"fieldVectors":[["name/0",[0,27.3]],["parent/0",[]],["name/1",[1,22.192]],["parent/1",[]],["name/2",[2,27.3]],["parent/2",[1,2.034]],["name/3",[3,27.3]],["parent/3",[]],["name/4",[4,14.307]],["parent/4",[]],["name/5",[5,27.3]],["parent/5",[4,1.312]],["name/6",[6,27.3]],["parent/6",[4,1.312]],["name/7",[7,22.192]],["parent/7",[8,0.811]],["name/8",[9,27.3]],["parent/8",[8,0.811]],["name/9",[10,27.3]],["parent/9",[8,0.811]],["name/10",[11,22.192]],["parent/10",[8,0.811]],["name/11",[12,27.3]],["parent/11",[8,0.811]],["name/12",[13,27.3]],["parent/12",[8,0.811]],["name/13",[14,27.3]],["parent/13",[8,0.811]],["name/14",[15,27.3]],["parent/14",[8,0.811]],["name/15",[16,27.3]],["parent/15",[8,0.811]],["name/16",[4,14.307]],["parent/16",[4,1.312]],["name/17",[17,27.3]],["parent/17",[18,1.312]],["name/18",[7,22.192]],["parent/18",[18,1.312]],["name/19",[11,22.192]],["parent/19",[18,1.312]],["name/20",[19,27.3]],["parent/20",[18,1.312]],["name/21",[20,27.3]],["parent/21",[18,1.312]]],"invertedIndex":[["__type",{"_index":2,"name":{"2":{}},"parent":{}}],["action",{"_index":5,"name":{"5":{}},"parent":{}}],["actiongenerator",{"_index":3,"name":{"3":{}},"parent":{}}],["actions",{"_index":10,"name":{"9":{}},"parent":{}}],["constructor",{"_index":17,"name":{"17":{}},"parent":{}}],["dict",{"_index":0,"name":{"0":{}},"parent":{}}],["effects",{"_index":14,"name":{"13":{}},"parent":{}}],["initial",{"_index":7,"name":{"7":{},"18":{}},"parent":{}}],["mappedreaction",{"_index":16,"name":{"15":{}},"parent":{}}],["mappedselectors",{"_index":13,"name":{"12":{}},"parent":{}}],["mutation",{"_index":1,"name":{"1":{}},"parent":{"2":{}}}],["mutations",{"_index":12,"name":{"11":{}},"parent":{}}],["reactions",{"_index":15,"name":{"14":{}},"parent":{}}],["selectors",{"_index":11,"name":{"10":{},"19":{}},"parent":{}}],["setaction",{"_index":20,"name":{"21":{}},"parent":{}}],["setmutation",{"_index":19,"name":{"20":{}},"parent":{}}],["subduxes",{"_index":9,"name":{"8":{}},"parent":{}}],["updux",{"_index":4,"name":{"4":{},"16":{}},"parent":{"5":{},"6":{},"16":{}}}],["updux\".updux",{"_index":18,"name":{},"parent":{"17":{},"18":{},"19":{},"20":{},"21":{}}}],["updux\".upduxconfig",{"_index":8,"name":{},"parent":{"7":{},"8":{},"9":{},"10":{},"11":{},"12":{},"13":{},"14":{},"15":{}}}],["upduxconfig",{"_index":6,"name":{"6":{}},"parent":{}}]],"pipeline":[]}} \ No newline at end of file diff --git a/docs/API/modules/_updux_.html b/docs/API/modules/_updux_.html index 75318cb..584b20b 100644 --- a/docs/API/modules/_updux_.html +++ b/docs/API/modules/_updux_.html @@ -1 +1,3 @@ -"updux" | Updux
Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace "updux"

Generated using TypeDoc

\ No newline at end of file +"updux" | Updux
Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace "updux"

Index

Classes

Interfaces

Functions

Functions

action

  • +

    Creates an action generator.

    +

    Parameters

    • type: string
    • Optional payloadFunction: Function

    Returns ActionGenerator

Generated using TypeDoc

\ No newline at end of file diff --git a/docs/concepts.md b/docs/concepts.md index c33dcea..e71f6a5 100644 --- a/docs/concepts.md +++ b/docs/concepts.md @@ -1,12 +1,32 @@ # Updux concepts -## actions +## Actions and action generators -Updux internally uses the package `ts-action` to create action creator -functions. Even if you don't use Typescript, I recommend that you use it, -as it does what it does very well. But if you don't want to, no big deal. -Updux will recognize a function as an action creator if it has a `type` -property. So a homegrown creator could be as simple as: +Updux assumes actions following the format + +```js +{ + type: 'theTypeName', + payload: { + ... + } +} +``` + +The important part is having action parameters in the `payload` property. The +actions can also have other properties, like `meta`. They are mostly ignored +by Updux. + + +Updux provides an action generator, but you can roll your own if you do wish. +All it needs to do to be recognized as an action generator by Updux is + +1. To be a function returning an action (a plain object with at least a + `type` property). +2. The function also needs to have a `type` property itself. + + +For example, the following function would work: ```js function action(type) { @@ -14,7 +34,36 @@ function action(type) { } ``` -## effects +### Mutations + +The transformations typically +done by a Redux's reducer are called 'mutations' in Updux. A mutation is a +function with the following signature: + +``` +( payload, action ) => state => { + // ... stuff done here + return new_state; +} +``` + +The inversion and chaining of parameters from the usual Redux reducer's +signature is there to work with updeep's curried nature. The expansion of +the usual `action` into `(payload, action)` is present because in most cases +`payload` is what we're interested in. So why not make it easily available? + +### Leftover mutation + +A mutation associated to the special action `+` will match any action that haven't been +explicitly dealt with with any other defined mutation. + +``` +todosUpdux.addMutation( '+', (payload,action) => state => { + console.log("hey, action has no mutation! ", action.type); +}); +``` + +## Effects Updux effects are redux middlewares. I kept that format, and the use of `next` mostly because I wanted to give myself a way to alter diff --git a/docs/tutorial.md b/docs/tutorial.md index 6671f3d..67dd65d 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -44,142 +44,40 @@ todosDux.setAction( 'addTodo' ); todosDux.setAction( 'todoDone' ); ``` -Now, there is a lot of ways to add actions to a Updux object. - -It can be defined when the object is created: - -``` -const todosUpdux = new Updux({ - actions: { - add_todo, - todo_done, - } -}); -``` - -It can be done via the method `addAction`: - -``` -todosUpdux.addAction(add_todo); -``` - -Or it can be directly used in the definition of a mutation or effect, and will -be automatically added to the Updux. - -``` -todosUpdux.addMutation( add_todo, todoMutation ); -``` - -For TypeScript projects I recommend declaring the actions as part of the -configuration passed to the constructors, as it makes them accessible to the class -at compile-time, and allows Updux to auto-add them to its aggregated `actions` type. - -``` -const todosUpdux = new Updux({ - actions: { - add_todo, - } -}); - -todosUpdux.addAction(todo_done); - -// only `add_todo` is visible to the type -type MyActions = typeof todosUpdux.actions; -// { add_todo: Function } - -// but both actions are accessible at runtime -const myAction = ( todosUpdux.actions as any).todo_done(1); -``` - ### Accessing actions Once an action is defined, its creator is accessible via the `actions` accessor. +```js +console.log( todosDux.actions.addTodo('write tutorial') ); // prints { type: 'addTodo', payload: 'write tutorial' } ``` -console.log( todosUpdux.actions.add_todo('write tutorial') ); -// { type: 'add_todo', payload: 'write tutorial' } -``` - -### What is an action? - -In this tutorial we use `ts-action` for all the work, but under the hood Updux defines actions via -their creators, which are expected to be: - -1. Functions, -2. returning a plain object of the format `{ type: string; payload?: unknown }`. -3. with an additional property `type`, which is also the action type. - -For example, this is a perfectly cromulent action: - -``` -const add_todo = description => ({ type: 'add_todo', payload: description}); -add_todo.type = 'add_todo'; -``` - -## Mutations - -Actions that don't do anything are not fun. The transformations typically -done by a Redux's reducer are called 'mutations' in Updux. A mutation is a -function with the following signature: - -``` -( payload, action ) => state => { - // ... stuff done here - return new_state; -} -``` - -The inversion and chaining of parameters from the usual Redux reducer's -signature is there to work with `updeep`'s curried nature. The expansion of -the usual `action` into `(payload, action)` is present because in most cases -`payload` is what we're interested in. So why not make it easily available? ### Adding a mutation -As for the actions, a mutation can be defined as part of the Updux +Like actions, a mutation can be defined as part of the Updux init arguments: -``` -const add_todo_mutation = description => ({next_id: id, todos}) => { - return { - next_id: 1 + id, - todos: [...todos, { description, id, done: false }] - } - -}; - -const todosUpdux = new Updux({ - actions: { add_todo }, - mutations: [ - [ add_todo, add_todo_mutation ] - ] -}); -``` - -or via the method `addMutation`: - -``` -todos.addMutation( add_todo, description => ({next_id: id, todos}) => { - return { - next_id: 1 + id, - todos: [...todos, { description, id, done: false }] +```js +const todosDux = new Updux({ + actions: { + addTodo: null + }, + mutations: { + addTodo: description => ({next_id: id, todos}) => ({ + next_id: 1 + id, + todos: [...todos, { description, id, done: false }] + }) } }); ``` -This time around, if the project is using TypeScript then the addition of -mutations via `addMutation` is encouraged, as the method signature -has visibility of the types of the action and state. +or via the method `setMutation`: -### Leftover mutation - -A mutation with the special action `*` will match any action that haven't been -explicitly dealt with with any other defined mutation. - -``` -todosUpdux.addMutation( '*', (payload,action) => state => { - console.log("hey, action has no mutation! ", action.type); -}); +```js +todosDux.setMutation( 'addTodo', description => ({next_id: id, todos}) => ({ + next_id: 1 + id, + todos: [...todos, { description, id, done: false }] +})); ``` ## Effects diff --git a/src/Updux.js b/src/Updux.js index 007c3e7..07bb112 100644 --- a/src/Updux.js +++ b/src/Updux.js @@ -54,7 +54,7 @@ export class Updux { this.#mutations = config.mutations ?? {}; Object.keys(this.#mutations) - .filter((action) => action !== '*') + .filter((action) => action !== '+') .filter((action) => !this.actions.hasOwnProperty(action)) .forEach((action) => { throw new Error(`action '${action}' is not defined`); diff --git a/src/buildUpreducer.js b/src/buildUpreducer.js index 71ccada..6486e19 100644 --- a/src/buildUpreducer.js +++ b/src/buildUpreducer.js @@ -26,7 +26,7 @@ export function buildUpreducer(initial, mutations, subduxes = {}) { } } - const a = mutations[action.type] || mutations['*']; + const a = mutations[action.type] || mutations['+']; if (!a) return newState; diff --git a/src/documentation.test.js b/src/documentation.test.js index e6bf6c2..a62ed57 100644 --- a/src/documentation.test.js +++ b/src/documentation.test.js @@ -45,4 +45,6 @@ test('tutorial', async (t) => { todosDux.setAction( 'addTodo' ); todosDux.setAction( 'todoDone' ); + t.same( todosDux.actions.addTodo('write tutorial') , { type: 'addTodo', payload: 'write tutorial' }); + }) diff --git a/src/index.js b/src/index.js index fb808a9..e0135b8 100644 --- a/src/index.js +++ b/src/index.js @@ -1,2 +1,2 @@ export { Updux } from './Updux.js'; - +export { action } from './actions.js'; diff --git a/src/mutations.test.js b/src/mutations.test.js index 5979409..e7ce90c 100644 --- a/src/mutations.test.js +++ b/src/mutations.test.js @@ -27,7 +27,7 @@ test('override', async (t) => { const dux = new Updux({ initial: { alpha: [] }, mutations: { - '*': (payload, action) => (state) => ({ + '+': (payload, action) => (state) => ({ ...state, alpha: [...state.alpha, action.type], }), diff --git a/types/index.d.ts b/types/index.d.ts index f271176..9ac6d51 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -95,4 +95,12 @@ declare module 'updux' { */ setAction(actionType: string, payloadFunc?: Function); } + + /** + * Creates an action generator. + */ + export function action( + actionType: string, + payloadFunction?: Function + ): ActionGenerator; }