Compare commits
159 Commits
v1.0.0
...
typescript
Author | SHA1 | Date |
---|---|---|
Yanick Champoux | ace7368b1b | |
Yanick Champoux | 624a60cb7f | |
Yanick Champoux | 82f5d53df2 | |
Yanick Champoux | f206026087 | |
Yanick Champoux | 7f1bcbddef | |
Yanick Champoux | 0b0ea7ea66 | |
Yanick Champoux | dd0dda0970 | |
Yanick Champoux | 23724931e9 | |
Yanick Champoux | 13c9603251 | |
Yanick Champoux | 82e8ba7385 | |
Yanick Champoux | 27e27aa70d | |
Yanick Champoux | 1255876c38 | |
Yanick Champoux | 6b508c9db2 | |
Yanick Champoux | 16397ce3ee | |
Yanick Champoux | fbe624a14c | |
Yanick Champoux | 702a3e76d4 | |
Yanick Champoux | 0f3aeff396 | |
Yanick Champoux | 3e6d2dae55 | |
Yanick Champoux | 51421c1052 | |
Yanick Champoux | 63d8235346 | |
Yanick Champoux | 141d959d28 | |
Yanick Champoux | c5ca566c12 | |
Yanick Champoux | 7583f9e98b | |
Yanick Champoux | e3dce45f50 | |
Yanick Champoux | 80a356ff1a | |
Yanick Champoux | af6db3403c | |
Yanick Champoux | c8bb1e5096 | |
Yanick Champoux | 9255548326 | |
Yanick Champoux | b4a96b67ea | |
Yanick Champoux | fa3300004d | |
Yanick Champoux | 378d61337f | |
Yanick Champoux | d12d114af8 | |
Yanick Champoux | 36b19316ba | |
Yanick Champoux | 6a4525f507 | |
Yanick Champoux | d44986e990 | |
Yanick Champoux | 34acc63bef | |
Yanick Champoux | 43702fe096 | |
Yanick Champoux | 3bb9221c27 | |
Yanick Champoux | 6cb7f14407 | |
Yanick Champoux | 6a6bb1636a | |
Yanick Champoux | 7494fe553e | |
Yanick Champoux | 325ad47731 | |
Yanick Champoux | b96f5e72ac | |
Yanick Champoux | fa837a345e | |
Yanick Champoux | e0ffaef07a | |
Yanick Champoux | c609a19ef8 | |
Yanick Champoux | 46b0565819 | |
Yanick Champoux | 3c78f34d5b | |
Yanick Champoux | 9772ce4bec | |
Yanick Champoux | 4d4a5dde50 | |
Yanick Champoux | 64782096df | |
Yanick Champoux | d20f50e156 | |
Yanick Champoux | 38c91d435f | |
Yanick Champoux | f2468e3b82 | |
Yanick Champoux | ef5751eb69 | |
Yanick Champoux | 3aac2e092e | |
Yanick Champoux | bb5218d2f6 | |
Yanick Champoux | ce666b75bb | |
Yanick Champoux | a272ee0329 | |
Yanick Champoux | f51c8158fc | |
Yanick Champoux | 541790425a | |
Yanick Champoux | f1b7677f0f | |
Yanick Champoux | 8314ff94ca | |
Yanick Champoux | 88d62536ad | |
Yanick Champoux | 707d9ec923 | |
Yanick Champoux | 4e4fa13d90 | |
Yanick Champoux | 27958a6d14 | |
Yanick Champoux | 85e478c02f | |
Yanick Champoux | a8f97940e8 | |
Yanick Champoux | 55812ed6d8 | |
Yanick Champoux | 7cd7e27805 | |
Yanick Champoux | c5a9a7397a | |
Yanick Champoux | 69a8781b4b | |
Yanick Champoux | a657813415 | |
Yanick Champoux | 440c76d408 | |
Yanick Champoux | 3394a00419 | |
Yanick Champoux | 83f28a1720 | |
Yanick Champoux | 6fb14a26d0 | |
Yanick Champoux | 33ded1448e | |
Yanick Champoux | 8c026314f5 | |
Yanick Champoux | d75da07d3f | |
Yanick Champoux | 6dd8b1af9e | |
Yanick Champoux | 9778e04a8d | |
Yanick Champoux | 2e357b71e2 | |
Yanick Champoux | a5e8410768 | |
Yanick Champoux | d14eb08bf0 | |
Yanick Champoux | 912ea85edc | |
Yanick Champoux | c1c1edf588 | |
Yanick Champoux | 5eeb4d4ab7 | |
Yanick Champoux | d61c9478a2 | |
Yanick Champoux | 5247aa2255 | |
Yanick Champoux | 04159ec7cc | |
Yanick Champoux | 2c26f9652b | |
Yanick Champoux | e4eff8a113 | |
Yanick Champoux | b7ada06e3c | |
Yanick Champoux | 0ecb1059ee | |
Yanick Champoux | 1759ce16c6 | |
Yanick Champoux | 1a653fac5b | |
Yanick Champoux | 0870767994 | |
Yanick Champoux | fd064f5996 | |
Yanick Champoux | 003a1309bd | |
Yanick Champoux | c96a6ea07c | |
Yanick Champoux | 1f62028e4e | |
Yanick Champoux | 74c29ce2d0 | |
Yanick Champoux | 99ba091a51 | |
Yanick Champoux | a39715f0a8 | |
Yanick Champoux | 7eab50ff60 | |
Yanick Champoux | 0ebf32c71b | |
Yanick Champoux | afc1a14f56 | |
Yanick Champoux | 9c45ee7efc | |
Yanick Champoux | 86dd272603 | |
Yanick Champoux | f0c1d6f015 | |
Yanick Champoux | 38199a5ec7 | |
Yanick Champoux | 97f21aac2a | |
Trey Bianchini | 84a9c4f77f | |
Yanick Champoux | 26bf0c962a | |
Trey Bianchini | f8edbcaa49 | |
Yanick Champoux | f0653442f3 | |
Yanick Champoux | e3c5aad399 | |
Yanick Champoux | dce52c56d0 | |
Yanick Champoux | 6349d720b8 | |
Yanick Champoux | f6b7c2b15a | |
Yanick Champoux | a71d3f8781 | |
Yanick Champoux | b7339c25e5 | |
Yanick Champoux | 4665ee39f7 | |
Yanick Champoux | 91923bfd49 | |
Yanick Champoux | 64a36c4088 | |
Yanick Champoux | e7fbd582fc | |
Yanick Champoux | 4c0d7b366f | |
Yanick Champoux | 931377b584 | |
Yanick Champoux | f744616cb2 | |
Yanick Champoux | 1825e8d269 | |
Yanick Champoux | 499e987219 | |
Yanick Champoux | 27ae46dbab | |
Yanick Champoux | 7ddc187f2b | |
Yanick Champoux | c8f497f5e9 | |
Yanick Champoux | 1388282d81 | |
Yanick Champoux | 4acfe5b17e | |
Yanick Champoux | 0d0890ffff | |
Yanick Champoux | fa55762efc | |
Yanick Champoux | 93bebc5acf | |
Yanick Champoux | fe34d01a41 | |
Yanick Champoux | 54ad7f2512 | |
Yanick Champoux | d90d72148c | |
Yanick Champoux | 73c2776826 | |
Yanick Champoux | 5465c53cb5 | |
Yanick Champoux | e78568b3cb | |
Yanick Champoux | 057226dfd1 | |
Yanick Champoux | 5c5e614f4b | |
Yanick Champoux | 8d4542fffa | |
Yanick Champoux | 9b5a7981d5 | |
Yanick Champoux | 74d29d3126 | |
Yanick Champoux | 1379055264 | |
Yanick Champoux | da7ac2ef6e | |
Yanick Champoux | 47b78f43cc | |
Yanick Champoux | 0d298cb285 | |
Yanick Champoux | 15e154b6ec | |
Yanick Champoux | 0e03628502 | |
Yanick Champoux | 73973a9588 |
|
@ -0,0 +1 @@
|
|||
out/
|
|
@ -0,0 +1,26 @@
|
|||
module.exports = {
|
||||
parserOptions: {
|
||||
ecmaVersion: 'latest',
|
||||
sourceType: 'module',
|
||||
},
|
||||
env: {
|
||||
es6: true,
|
||||
browser: true,
|
||||
},
|
||||
plugins: ['todo-plz', 'no-only-tests'],
|
||||
overrides: [],
|
||||
rules: {
|
||||
'no-console': ['error'],
|
||||
'todo-plz/ticket-ref': ['error', { pattern: 'GT[0-9]+' }],
|
||||
'no-only-tests/no-only-tests': [
|
||||
'error',
|
||||
{
|
||||
block: ['test'],
|
||||
focus: ['only'],
|
||||
},
|
||||
],
|
||||
},
|
||||
settings: {
|
||||
// ...
|
||||
},
|
||||
};
|
|
@ -1,2 +1,11 @@
|
|||
node_modules/
|
||||
tsconfig.tsbuildinfo
|
||||
**/*.orig
|
||||
dist
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
.nyc_output/
|
||||
pnpm-debug.log
|
||||
yarn-error.log
|
||||
GPUCache/
|
||||
updux-2.0.0.tgz
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
*.test.*
|
||||
test.*
|
||||
docs
|
||||
node_modules/
|
||||
tsconfig.tsbuildinfo
|
||||
**/*.orig
|
||||
dist
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
.nyc_output/
|
||||
pnpm-debug.log
|
||||
pnpm-lock.yaml
|
||||
yarn-error.log
|
||||
GPUCache/
|
||||
updux-2.0.0.tgz
|
||||
.travis.yml
|
||||
.prettierignore
|
||||
tools/gen_sidebar.pl
|
|
@ -0,0 +1,22 @@
|
|||
exclude: static/fontawesome|^build
|
||||
|
||||
default_stages:
|
||||
- merge-commit
|
||||
- push
|
||||
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.3.0
|
||||
hooks:
|
||||
- id: end-of-file-fixer
|
||||
stages: [merge-commit, push]
|
||||
- id: trailing-whitespace
|
||||
stages: [merge-commit, push]
|
||||
- id: check-merge-conflict
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: lint
|
||||
name: lint
|
||||
entry: task lint:fix --
|
||||
language: system
|
||||
files: ''
|
|
@ -0,0 +1,7 @@
|
|||
dist
|
||||
out
|
||||
pnpm-lock.yaml
|
||||
types
|
||||
docs
|
||||
Changes
|
||||
.prettierignore
|
|
@ -0,0 +1,9 @@
|
|||
module.exports = {
|
||||
semi: true,
|
||||
trailingComma: 'all',
|
||||
singleQuote: true,
|
||||
printWidth: 80,
|
||||
tabWidth: 4,
|
||||
useTabs: false,
|
||||
plugins: [],
|
||||
};
|
14
.travis.yml
14
.travis.yml
|
@ -1,16 +1,16 @@
|
|||
language: node_js
|
||||
|
||||
node_js:
|
||||
- 'node'
|
||||
- 'lts/*'
|
||||
- 'node'
|
||||
- 'lts/*'
|
||||
|
||||
install:
|
||||
- npm uninstall typescript --no-save
|
||||
- npm install
|
||||
- npm uninstall typescript --no-save
|
||||
- npm install
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
directories:
|
||||
- node_modules
|
||||
|
||||
git:
|
||||
depth: 1
|
||||
depth: 1
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
|
||||
## 4.0.0 (2022-08-30)
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
- Return to a JavaScript core (sorry Typescript).
|
||||
|
||||
## 3.0.0 (2021-05-02)
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
- Upgrade to Typescript 4.
|
||||
- Switch from 'updeep' to '@yanick/updeep'.
|
||||
|
||||
## [2.1.0](https://github.com/yanick/updux/compare/v2.0.0...v2.1.0) (2020-06-19)
|
||||
|
||||
### Features
|
||||
|
||||
- add support for subscriptions ([9c45ee7](https://github.com/yanick/updux/commit/9c45ee7efcb623defb9da5d01165fbad0e4424f9))
|
||||
|
||||
## [2.0.0](https://github.com/yanick/updux/compare/v1.2.0...v2.0.0) (2020-06-13)
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
- use ts-action for action creation
|
||||
- middleware support refined
|
||||
|
||||
### Features
|
||||
|
||||
- allow adding actionCreators via addAction() ([27ae46d](https://github.com/yanick/updux/commit/27ae46dbab289b27ea99aca149aaa3b7c90ee7d0))
|
||||
- middleware support refined ([d90d721](https://github.com/yanick/updux/commit/d90d72148c2d4ba186a19650d961c64df5791c55))
|
||||
- moving documentation to docsify ([fa55762](https://github.com/yanick/updux/commit/fa55762efcbd4db356150f6022fd62750adc27a9))
|
||||
- use ts-action for action creation ([6349d72](https://github.com/yanick/updux/commit/6349d720b8aba4b443a7225d6a377c5c929a3021))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- state is a PreloadedState<S> ([93bebc5](https://github.com/yanick/updux/commit/93bebc5acf193752aa6b4857507f05d52b1b7665))
|
||||
|
||||
## 1.2.0 2019-11-06
|
||||
|
||||
- The middleware's 'getState' returns the local state of its updux,
|
||||
instead of the root state. Plus we add `getRootState` to get
|
||||
the root state.
|
||||
|
||||
## 1.1.0 2019-11-05
|
||||
|
||||
- Document mapping behavior of the '*' subdux.
|
||||
- add subduxUpreducer.
|
||||
- add sink mutations.
|
||||
|
||||
## 1.0.0 2019-11-04
|
||||
|
||||
- Pretty big rework.
|
||||
- Better documentation.
|
||||
|
||||
## 0.2.0 2019-10-24
|
||||
|
||||
- Converted everything to Typescript.
|
||||
|
||||
## 0.1.0 2019-10-22
|
||||
|
||||
- Add 'actions' in the config.
|
||||
|
||||
## 0.0.1 2019-10-22
|
||||
|
||||
- Initial release.
|
|
@ -0,0 +1,128 @@
|
|||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our
|
||||
community a harassment-free experience for everyone, regardless of age, body
|
||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||
identity and expression, level of experience, education, socio-economic status,
|
||||
nationality, personal appearance, race, religion, or sexual identity
|
||||
and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||
diverse, inclusive, and healthy community.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
- Demonstrating empathy and kindness toward other people
|
||||
- Being respectful of differing opinions, viewpoints, and experiences
|
||||
- Giving and gracefully accepting constructive feedback
|
||||
- Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
- Focusing on what is best not just for us as individuals, but for the
|
||||
overall community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
- The use of sexualized language or imagery, and sexual attention or
|
||||
advances of any kind
|
||||
- Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
- Public or private harassment
|
||||
- Publishing others' private information, such as a physical or email
|
||||
address, without their explicit permission
|
||||
- Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of
|
||||
acceptable behavior and will take appropriate and fair corrective action in
|
||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||
or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||
decisions when appropriate.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when
|
||||
an individual is officially representing the community in public spaces.
|
||||
Examples of representing our community include using an official e-mail address,
|
||||
posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported to the community leaders responsible for enforcement at
|
||||
[yanick@babyl.ca](mailto://yanick@babyl.ca).
|
||||
All complaints will be reviewed and investigated promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the
|
||||
reporter of any incident.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining
|
||||
the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series
|
||||
of actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or
|
||||
permanent ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within
|
||||
the community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 2.0, available at
|
||||
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
||||
|
||||
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
||||
enforcement ladder](https://github.com/mozilla/diversity).
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
https://www.contributor-covenant.org/faq. Translations are available at
|
||||
https://www.contributor-covenant.org/translations.
|
14
Changes
14
Changes
|
@ -1,14 +0,0 @@
|
|||
# Revision history for Updux
|
||||
|
||||
1.0.0 2019-11-04
|
||||
- Pretty big rework.
|
||||
- Better documentation.
|
||||
|
||||
0.2.0 2019-10-24
|
||||
- Converted everything to Typescript.
|
||||
|
||||
0.1.0 2019-10-22
|
||||
- Add 'actions' in the config.
|
||||
|
||||
0.0.1 2019-10-22
|
||||
- Initial release.
|
104
README.md
104
README.md
|
@ -1,12 +1,11 @@
|
|||
|
||||
# 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.
|
||||
[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
|
||||
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
|
||||
|
@ -16,17 +15,16 @@ is the fun in that? And I'm also having a strong love for
|
|||
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
|
||||
- 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,
|
||||
- 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.
|
||||
|
||||
- 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
|
||||
|
@ -45,7 +43,7 @@ const {
|
|||
actions,
|
||||
middleware,
|
||||
createStore,
|
||||
} = new Updux({
|
||||
} = new Updux({
|
||||
initial: {
|
||||
counter: 0,
|
||||
},
|
||||
|
@ -62,9 +60,9 @@ const {
|
|||
};
|
||||
},
|
||||
actions: {
|
||||
customAction: ( someArg ) => ({
|
||||
type: "custom",
|
||||
payload: { someProp: someArg }
|
||||
customAction: ( someArg ) => ({
|
||||
type: "custom",
|
||||
payload: { someProp: someArg }
|
||||
}),
|
||||
},
|
||||
|
||||
|
@ -77,8 +75,9 @@ store.dispatch.inc(3);
|
|||
|
||||
# Description
|
||||
|
||||
The formal documentation of the class Updux and its associated functions and
|
||||
types can be found over [here](./docs/classes/updux.html).
|
||||
Full documentation can be [found here](https://yanick.github.io/updux/).
|
||||
Right now the best way to understand the whole thing is to go
|
||||
through the [tutorial](https://yanick.github.io/updux/#/tutorial)
|
||||
|
||||
## Exporting upduxes
|
||||
|
||||
|
@ -95,7 +94,6 @@ const updux = new Updux({ ... });
|
|||
export default updux;
|
||||
```
|
||||
|
||||
|
||||
Then you can use them as subduxes like this:
|
||||
|
||||
```
|
||||
|
@ -123,6 +121,59 @@ const {
|
|||
} = 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
|
||||
|
@ -136,15 +187,14 @@ import Updux from 'updux';
|
|||
const updux = new Updux({
|
||||
initial: { counter: 0 },
|
||||
mutations: {
|
||||
add: (inc=1) => state => { counter: counter + inc }
|
||||
add: (inc=1) => state => { counter: counter + inc }
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
```
|
||||
|
||||
Converting it to Immer would look like:
|
||||
|
||||
|
||||
```
|
||||
import Updux from 'updux';
|
||||
import { produce } from 'Immer';
|
||||
|
@ -152,16 +202,15 @@ import { produce } from 'Immer';
|
|||
const updux = new Updux({
|
||||
initial: { counter: 0 },
|
||||
mutations: {
|
||||
add: (inc=1) => produce( draft => draft.counter += inc ) }
|
||||
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';
|
||||
|
@ -170,11 +219,8 @@ const updux = new Updux({
|
|||
initial: { counter: 0 },
|
||||
groomMutations: mutation => (...args) => produce( mutation(...args) ),
|
||||
mutations: {
|
||||
add: (inc=1) => draft => draft.counter += inc
|
||||
add: (inc=1) => draft => draft.counter += inc
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
|
9
TODO
9
TODO
|
@ -1,7 +1,2 @@
|
|||
[ ] Warn if one tries to define the same action twice
|
||||
[ ] Middleware of subduxes get sub-states and getRootState
|
||||
[ ] add `addAction` method
|
||||
[ ] can do .addMutation( 'foo', ... );, which either
|
||||
use the action already existing or create a boring one (should I?)
|
||||
|
||||
|
||||
- documentation generator (mkdocs + jsdoc-to-markdown)
|
||||
- createStore
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
# https://taskfile.dev
|
||||
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
lint:fix:delta:
|
||||
vars:
|
||||
FILES:
|
||||
sh: git diff-ls --diff-filter=d main | grep -v .vitebook
|
||||
deps:
|
||||
- task: 'lint:fix'
|
||||
vars:
|
||||
CLI_ARGS: '{{.FILES | catLines }}'
|
||||
|
||||
lint:
|
||||
cmds:
|
||||
- npx prettier --check {{.CLI_ARGS | default "." }}
|
||||
- npx eslint {{.CLI_ARGS | default "." }}
|
||||
|
||||
lint:fix:
|
||||
cmds:
|
||||
- npx prettier --write {{.CLI_ARGS | default "." }}
|
||||
- npx eslint --fix --quiet {{.CLI_ARGS | default "." }}
|
||||
|
||||
lint:delta:
|
||||
cmds:
|
||||
- task: 'lint:prettier:delta'
|
||||
- task: 'lint:eslint:delta'
|
||||
|
||||
lint:prettier:delta:
|
||||
vars:
|
||||
FILES:
|
||||
sh: git diff-ls --diff-filter=d {{.ROOT_BRANCH | default "main"}} | grep -v .vitebook
|
||||
cmds:
|
||||
- npx prettier --check {{.FILES | catLines }}
|
||||
|
||||
lint:eslint:delta:
|
||||
vars:
|
||||
FILES:
|
||||
sh: git diff-ls --diff-filter=d {{.ROOT_BRANCH | default "main"}} | grep -v .vitebook
|
||||
cmds:
|
||||
- npx eslint --format=unix {{.FILES | catLines }}
|
||||
|
||||
lint:eslint:
|
||||
cmds:
|
||||
- npx eslint {{.FILES | default "src/**" }}
|
|
@ -1,12 +0,0 @@
|
|||
module.exports = {
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
targets: {
|
||||
node: 'current',
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
|
@ -1,2 +0,0 @@
|
|||
export {};
|
||||
//# sourceMappingURL=actions.test.d.ts.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"actions.test.d.ts","sourceRoot":"","sources":["../src/actions.test.ts"],"names":[],"mappings":""}
|
|
@ -1,37 +0,0 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const _1 = __importDefault(require("."));
|
||||
const noopEffect = () => () => () => { };
|
||||
test('actions defined in effects and mutations, multi-level', () => {
|
||||
const { actions } = new _1.default({
|
||||
effects: {
|
||||
foo: noopEffect,
|
||||
},
|
||||
mutations: { bar: () => () => null },
|
||||
subduxes: {
|
||||
mysub: {
|
||||
effects: { baz: noopEffect },
|
||||
mutations: { quux: () => () => null },
|
||||
actions: {
|
||||
foo: (limit) => ({ limit }),
|
||||
},
|
||||
},
|
||||
myothersub: {
|
||||
effects: {
|
||||
foo: noopEffect,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const types = Object.keys(actions);
|
||||
types.sort();
|
||||
expect(types).toEqual(['bar', 'baz', 'foo', 'quux']);
|
||||
expect(actions.bar()).toEqual({ type: 'bar' });
|
||||
expect(actions.bar('xxx')).toEqual({ type: 'bar', payload: 'xxx' });
|
||||
expect(actions.bar(undefined, 'yyy')).toEqual({ type: 'bar', meta: 'yyy' });
|
||||
expect(actions.foo(12)).toEqual({ type: 'foo', payload: { limit: 12 } });
|
||||
});
|
||||
//# sourceMappingURL=actions.test.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"actions.test.js","sourceRoot":"","sources":["../src/actions.test.ts"],"names":[],"mappings":";;;;;AAAA,yCAAsB;AAGtB,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;AAExC,IAAI,CAAC,uDAAuD,EAAE,GAAG,EAAE;IACjE,MAAM,EAAC,OAAO,EAAC,GAAG,IAAI,UAAK,CAAC;QAC1B,OAAO,EAAE;YACP,GAAG,EAAE,UAAU;SAChB;QACD,SAAS,EAAE,EAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,EAAC;QAClC,QAAQ,EAAE;YACR,KAAK,EAAE;gBACL,OAAO,EAAE,EAAC,GAAG,EAAE,UAAU,EAAE;gBAC3B,SAAS,EAAE,EAAC,IAAI,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,EAAC;gBACnC,OAAO,EAAE;oBACP,GAAG,EAAE,CAAC,KAAY,EAAE,EAAE,CAAC,CAAC,EAAC,KAAK,EAAC,CAAC;iBACjC;aACF;YACD,UAAU,EAAE;gBACV,OAAO,EAAE;oBACP,GAAG,EAAE,UAAU;iBAChB;aACF;SACF;KACF,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnC,KAAK,CAAC,IAAI,EAAE,CAAC;IAEb,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IAErD,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,EAAC,IAAI,EAAE,KAAK,EAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,EAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAC,CAAC,CAAC;IAClE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,EAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAC,CAAC,CAAC;IAE1E,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EAAC,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,EAAC,KAAK,EAAE,EAAE,EAAC,EAAC,CAAC,CAAC;AACvE,CAAC,CAAC,CAAC"}
|
|
@ -1,2 +0,0 @@
|
|||
export {};
|
||||
//# sourceMappingURL=addMutations.test.d.ts.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"addMutations.test.d.ts","sourceRoot":"","sources":["../src/addMutations.test.ts"],"names":[],"mappings":""}
|
|
@ -1,22 +0,0 @@
|
|||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const updux_1 = __importStar(require("./updux"));
|
||||
test('added mutation is present', () => {
|
||||
const updux = new updux_1.default({
|
||||
initial: { sum: 0 },
|
||||
});
|
||||
const add = updux_1.actionCreator('add', (n) => ({ n }));
|
||||
updux.addMutation(add, ({ n }, action) => ({ sum }) => ({ sum: sum + n }));
|
||||
updux.mutations;
|
||||
const store = updux.createStore();
|
||||
store.dispatch.add(3);
|
||||
expect(store.getState()).toEqual({ sum: 3 });
|
||||
});
|
||||
//# sourceMappingURL=addMutations.test.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"addMutations.test.js","sourceRoot":"","sources":["../src/addMutations.test.ts"],"names":[],"mappings":";;;;;;;;;AAAA,iDAA+C;AAM/C,IAAI,CAAE,2BAA2B,EAAE,GAAG,EAAE;IACpC,MAAM,KAAK,GAAG,IAAI,eAAK,CAAU;QAC7B,OAAO,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE;KACtB,CAAC,CAAC;IAEH,MAAM,GAAG,GAAG,qBAAa,CAAC,KAAK,EAAE,CAAC,CAAU,EAAE,EAAE,CAAC,CAAC,EAAC,CAAC,EAAC,CAAC,CAAE,CAAA;IAGxD,KAAK,CAAC,WAAW,CACb,GAAG,EAAE,CAAC,EAAC,CAAC,EAAC,EAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAC,GAAG,EAAC,EAAE,EAAE,CAAC,CAAC,EAAC,GAAG,EAAE,GAAG,GAAG,CAAC,EAAC,CAAC,CACnD,CAAC;IACF,KAAK,CAAC,SAAS,CAAC;IAChB,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IAClC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAEtB,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;AACjD,CAAC,CAAC,CAAC"}
|
|
@ -1,8 +0,0 @@
|
|||
import { ActionCreator, ActionPayloadGenerator, Dictionary } from '../types';
|
||||
export declare function actionCreator<T extends string, P extends any>(type: T, transform: (...args: any[]) => P): ActionCreator<T, P>;
|
||||
export declare function actionCreator<T extends string>(type: T, transform: never): ActionCreator<T, undefined>;
|
||||
export declare function actionCreator<T extends string>(type: T, transform: null): ActionCreator<T, null>;
|
||||
declare type ActionPair = [string, ActionCreator];
|
||||
declare function buildActions(generators?: Dictionary<ActionPayloadGenerator>, actionNames?: string[], subActions?: ActionPair[]): Dictionary<ActionCreator>;
|
||||
export default buildActions;
|
||||
//# sourceMappingURL=index.d.ts.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/buildActions/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,aAAa,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAErF,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAC,CAAC,SAAS,GAAG,EAAG,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GAAI,aAAa,CAAC,CAAC,EAAC,CAAC,CAAC,CAAA;AAC9H,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAG,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,KAAK,GAAI,aAAa,CAAC,CAAC,EAAC,SAAS,CAAC,CAAA;AACxG,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAG,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,GAAI,aAAa,CAAC,CAAC,EAAC,IAAI,CAAC,CAAA;AA2BlG,aAAK,UAAU,GAAG,CAAE,MAAM,EAAE,aAAa,CAAE,CAAC;AAE5C,iBAAS,YAAY,CACnB,UAAU,GAAG,UAAU,CAAC,sBAAsB,CAAM,EACpD,WAAW,GAAE,MAAM,EAAO,EAC1B,UAAU,GAAG,UAAU,EAAO,GAC9B,UAAU,CAAC,aAAa,CAAC,CAkB1B;AAED,eAAe,YAAY,CAAC"}
|
|
@ -1,35 +0,0 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fp_1 = __importDefault(require("lodash/fp"));
|
||||
function actionCreator(type, transform) {
|
||||
if (transform) {
|
||||
return Object.assign((...args) => ({ type, payload: transform(...args) }), { type });
|
||||
}
|
||||
if (transform === null) {
|
||||
return Object.assign(() => ({ type }), { type });
|
||||
}
|
||||
return Object.assign((payload) => ({ type, payload }));
|
||||
}
|
||||
exports.actionCreator = actionCreator;
|
||||
function actionFor(type) {
|
||||
const f = ((payload = undefined, meta = undefined) => fp_1.default.pickBy(v => v !== undefined)({ type, payload, meta }));
|
||||
return Object.assign(f, {
|
||||
_genericAction: true,
|
||||
type
|
||||
});
|
||||
}
|
||||
function buildActions(generators = {}, actionNames = [], subActions = []) {
|
||||
const [crafted, generic] = fp_1.default.partition(([type, f]) => !f._genericAction)(subActions);
|
||||
const actions = [
|
||||
...(actionNames.map(type => [type, actionFor(type)])),
|
||||
...generic,
|
||||
...crafted,
|
||||
...Object.entries(generators).map(([type, payload]) => [type, payload.type ? payload : (...args) => ({ type, payload: payload(...args) })]),
|
||||
];
|
||||
return fp_1.default.fromPairs(actions);
|
||||
}
|
||||
exports.default = buildActions;
|
||||
//# sourceMappingURL=index.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/buildActions/index.ts"],"names":[],"mappings":";;;;;AAAA,mDAA2B;AAM3B,SAAgB,aAAa,CAAC,IAAQ,EAAE,SAAa;IAEjD,IAAI,SAAS,EAAG;QACZ,OAAO,MAAM,CAAC,MAAM,CAChB,CAAC,GAAG,IAAW,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,EACvD,EAAE,IAAI,EAAE,CAAE,CAAA;KACrB;IAED,IAAI,SAAS,KAAK,IAAI,EAAG;QACrB,OAAO,MAAM,CAAC,MAAM,CAAE,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,CAAE,CAAA;KACrD;IAED,OAAO,MAAM,CAAC,MAAM,CAAE,CAAC,OAAgB,EAAE,EAAE,CAAC,CAAC,EAAC,IAAI,EAAE,OAAO,EAAC,CAAC,CAAE,CAAC;AACpE,CAAC;AAbD,sCAaC;AAED,SAAS,SAAS,CAAC,IAAW;IAC5B,MAAM,CAAC,GAAG,CAAE,CAAC,OAAO,GAAG,SAAS,EAAE,IAAI,GAAG,SAAS,EAAE,EAAE,CACpD,YAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,EAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAC,CAAW,CACjE,CAAC;IAEF,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE;QACpB,cAAc,EAAE,IAAI;QACpB,IAAI;KACP,CAAC,CAAC;AACL,CAAC;AAID,SAAS,YAAY,CACnB,aAAkD,EAAE,EACpD,cAAwB,EAAE,EAC1B,aAA4B,EAAE;IAK9B,MAAM,CAAE,OAAO,EAAE,OAAO,CAAE,GAAG,YAAE,CAAC,SAAS,CACrC,CAAC,CAAC,IAAI,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,cAAc,CAClC,CAAE,UAAU,CAAE,CAAC;IAEd,MAAM,OAAO,GAAS;QAClB,GAAG,CAAC,WAAW,CAAC,GAAG,CAAE,IAAI,CAAC,EAAE,CAAC,CAAE,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,CAAE,CAAE,CAAC;QACzD,GAAG,OAAO;QACV,GAAG,OAAO;QACV,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAC7B,CAAC,CAAC,IAAI,EAAE,OAAO,CAAuB,EAAO,EAAE,CAAC,CAAC,IAAI,EAAG,OAAe,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,IAAS,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CACpJ;KACJ,CAAC;IAEF,OAAO,YAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAED,kBAAe,YAAY,CAAC"}
|
|
@ -1,24 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = buildCreateStore;
|
||||
|
||||
var _redux = require("redux");
|
||||
|
||||
function buildCreateStore(reducer, initial, middleware, actions) {
|
||||
return () => {
|
||||
const store = (0, _redux.createStore)(reducer, initial, (0, _redux.applyMiddleware)(middleware));
|
||||
|
||||
for (let a in actions) {
|
||||
store.dispatch[a] = (...args) => {
|
||||
store.dispatch(actions[a](...args));
|
||||
};
|
||||
}
|
||||
|
||||
return store;
|
||||
};
|
||||
}
|
||||
|
||||
;
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"buildCreateStore.js","sourceRoot":"","sources":["../src/buildCreateStore.js"],"names":[],"mappings":";;AAAA,iCAAyE;AAEzE,SAAwB,gBAAgB,CAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAC9B,OAAO;IAC3C,OAAO,GAAG,EAAE;QACV,MAAM,KAAK,GAAI,mBAAgB,CAAE,OAAO,EAAE,OAAO,EAC7C,uBAAe,CAAE,UAAU,CAAC,CAC7B,CAAC;QACJ,KAAM,IAAI,CAAC,IAAI,OAAO,EAAG;YACrB,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE;gBAC5B,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;YACvC,CAAC,CAAC;SACL;QAED,OAAO,KAAK,CAAC;IACjB,CAAC,CAAA;AACH,CAAC;AAdD,mCAcC;AAAA,CAAC"}
|
|
@ -1,7 +0,0 @@
|
|||
import { Middleware, Reducer } from 'redux';
|
||||
import { ActionCreator, Dictionary } from '../types';
|
||||
declare function buildCreateStore<S>(reducer: Reducer<S>, initial: S, middleware: Middleware, actions: Dictionary<ActionCreator>): () => import("redux").Store<S, import("redux").AnyAction> & {
|
||||
dispatch: {};
|
||||
};
|
||||
export default buildCreateStore;
|
||||
//# sourceMappingURL=index.d.ts.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/buildCreateStore/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,UAAU,EACV,OAAO,EACR,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAErD,iBAAS,gBAAgB,CAAC,CAAC,EACzB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,OAAO,EAAE,CAAC,EACV,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,UAAU,CAAC,aAAa,CAAC;;EAgBnC;AAED,eAAe,gBAAgB,CAAC"}
|
|
@ -1,16 +0,0 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const redux_1 = require("redux");
|
||||
function buildCreateStore(reducer, initial, middleware, actions) {
|
||||
return () => {
|
||||
const store = redux_1.createStore(reducer, initial, redux_1.applyMiddleware(middleware));
|
||||
for (let a in actions) {
|
||||
store.dispatch[a] = (...args) => {
|
||||
store.dispatch(actions[a](...args));
|
||||
};
|
||||
}
|
||||
return store;
|
||||
};
|
||||
}
|
||||
exports.default = buildCreateStore;
|
||||
//# sourceMappingURL=index.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/buildCreateStore/index.ts"],"names":[],"mappings":";;AAAA,iCAKe;AAGf,SAAS,gBAAgB,CACvB,OAAmB,EACnB,OAAU,EACV,UAAsB,EACtB,OAAkC;IAElC,OAAO,GAAG,EAAE;QACV,MAAM,KAAK,GAAG,mBAAgB,CAC5B,OAAO,EACP,OAAO,EACP,uBAAe,CAAC,UAAU,CAAC,CAC5B,CAAC;QACF,KAAK,IAAI,CAAC,IAAI,OAAO,EAAE;YACnB,KAAK,CAAC,QAAgB,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE;gBAC/C,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;YACtC,CAAC,CAAC;SACH;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAED,kBAAe,gBAAgB,CAAC"}
|
|
@ -1,5 +0,0 @@
|
|||
import { Dictionary } from '../types';
|
||||
declare function buildInitial<S extends number | string | boolean>(initial: S, subduxes?: Dictionary<undefined>): S;
|
||||
declare function buildInitial<S extends object>(initial?: Partial<S>, subduxes?: Partial<S>): S extends object ? S : never;
|
||||
export default buildInitial;
|
||||
//# sourceMappingURL=index.d.ts.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/buildInitial/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,iBAAS,YAAY,CAAC,CAAC,SAAS,MAAM,GAAC,MAAM,GAAC,OAAO,EAAG,OAAO,EAAE,CAAC,EAAE,QAAQ,CAAC,EAAE,UAAU,CAAC,SAAS,CAAC,GAAI,CAAC,CAAC;AAC1G,iBAAS,YAAY,CAAC,CAAC,SAAS,MAAM,EAAG,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,GAAI,CAAC,SAAS,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC;AAQrH,eAAe,YAAY,CAAC"}
|
|
@ -1,11 +0,0 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fp_1 = __importDefault(require("lodash/fp"));
|
||||
function buildInitial(initial = {}, subduxes = {}) {
|
||||
return fp_1.default.isPlainObject(initial) ? fp_1.default.mergeAll([subduxes, initial]) : initial;
|
||||
}
|
||||
exports.default = buildInitial;
|
||||
//# sourceMappingURL=index.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/buildInitial/index.ts"],"names":[],"mappings":";;;;;AAAA,mDAA2B;AAK3B,SAAS,YAAY,CACnB,UAAgB,EAAE,EAClB,WAAiB,EAAE;IAEnB,OAAO,YAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,YAAE,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AAChF,CAAC;AAED,kBAAe,YAAY,CAAC"}
|
|
@ -1 +0,0 @@
|
|||
"use strict";
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"index.test-d.js","sourceRoot":"","sources":["../../src/buildInitial/index.test-d.js"],"names":[],"mappings":""}
|
|
@ -1 +0,0 @@
|
|||
"use strict";
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"test-d.js","sourceRoot":"","sources":["../../src/buildInitial/test-d.js"],"names":[],"mappings":""}
|
|
@ -1,27 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = buildMiddleware;
|
||||
|
||||
var _fp = _interopRequireDefault(require("lodash/fp"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const MiddlewareFor = (type, mw) => api => next => action => {
|
||||
if (type !== '*' && action.type !== type) return next(action);
|
||||
return mw(api)(next)(action);
|
||||
};
|
||||
|
||||
function buildMiddleware(effects = {}, actions = {}, subduxes = {}) {
|
||||
return api => {
|
||||
for (let type in actions) {
|
||||
api.dispatch[type] = (...args) => api.dispatch(actions[type](...args));
|
||||
}
|
||||
|
||||
return original_next => {
|
||||
return [..._fp.default.toPairs(effects).map(([type, effect]) => MiddlewareFor(type, effect)), ..._fp.default.map('middleware', subduxes)].filter(x => x).reduceRight((next, mw) => mw(api)(next), original_next);
|
||||
};
|
||||
};
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"buildMiddleware.js","sourceRoot":"","sources":["../src/buildMiddleware.js"],"names":[],"mappings":";;;;;AAAA,mDAA2B;AAE3B,MAAM,aAAa,GAAG,CAAC,IAAI,EAAC,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE;IACvD,IAAI,IAAI,KAAK,GAAG,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;IAE9D,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC,CAAC;AAEF,SAAwB,eAAe,CACnC,OAAO,GAAG,EAAE,EACZ,OAAO,GAAG,EAAE,EACZ,QAAQ,GAAG,EAAE;IAEf,OAAO,GAAG,CAAC,EAAE;QACX,KAAK,IAAI,IAAI,IAAI,OAAO,EAAE;YACxB,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;SACxE;QAED,OAAO,aAAa,CAAC,EAAE;YACrB,OAAO;gBACL,GAAG,YAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,CAC1C,aAAa,CAAC,IAAI,EAAC,MAAM,CAAC,CAC7B;gBACD,GAAG,YAAE,CAAC,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC;aAClC;iBACE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;iBACd,WAAW,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,CAAC;QAC7D,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AArBD,kCAqBC"}
|
|
@ -1,5 +0,0 @@
|
|||
import { Middleware } from 'redux';
|
||||
import { Dictionary, ActionCreator, UpduxDispatch } from '../types';
|
||||
declare function buildMiddleware<S = any>(effects?: Dictionary<Middleware<{}, S, UpduxDispatch>>, actions?: Dictionary<ActionCreator>, subMiddlewares?: Middleware<{}, S, UpduxDispatch>[]): Middleware<{}, S, UpduxDispatch>;
|
||||
export default buildMiddleware;
|
||||
//# sourceMappingURL=index.d.ts.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/buildMiddleware/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAA2B,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,aAAa,EAAU,aAAa,EAAE,MAAM,UAAU,CAAC;AAU5E,iBAAS,eAAe,CAAC,CAAC,GAAC,GAAG,EAC1B,OAAO,GAAG,UAAU,CAAC,UAAU,CAAC,EAAE,EAAC,CAAC,EAAC,aAAa,CAAC,CAAK,EACxD,OAAO,GAAG,UAAU,CAAC,aAAa,CAAK,EACvC,cAAc,GAAE,UAAU,CAAC,EAAE,EAAC,CAAC,EAAC,aAAa,CAAC,EAAO,GACtD,UAAU,CAAC,EAAE,EAAC,CAAC,EAAC,aAAa,CAAC,CAoBhC;AAED,eAAe,eAAe,CAAC"}
|
|
@ -1,29 +0,0 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fp_1 = __importDefault(require("lodash/fp"));
|
||||
const MiddlewareFor = (type, mw) => api => next => action => {
|
||||
if (type !== '*' && action.type !== type)
|
||||
return next(action);
|
||||
return mw(api)(next)(action);
|
||||
};
|
||||
function buildMiddleware(effects = {}, actions = {}, subMiddlewares = []) {
|
||||
return (api) => {
|
||||
for (let type in actions) {
|
||||
const ac = actions[type];
|
||||
api.dispatch[type] = (...args) => api.dispatch(ac(...args));
|
||||
}
|
||||
return (original_next) => {
|
||||
return [
|
||||
...fp_1.default.toPairs(effects).map(([type, effect]) => MiddlewareFor(type, effect)),
|
||||
...subMiddlewares
|
||||
]
|
||||
.filter(x => x)
|
||||
.reduceRight((next, mw) => mw(api)(next), original_next);
|
||||
};
|
||||
};
|
||||
}
|
||||
exports.default = buildMiddleware;
|
||||
//# sourceMappingURL=index.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/buildMiddleware/index.ts"],"names":[],"mappings":";;;;;AAAA,mDAA2B;AAK3B,MAAM,aAAa,GAAG,CAAC,IAAS,EAAE,EAAc,EAAe,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE;IACtF,IAAI,IAAI,KAAK,GAAG,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;IAE9D,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC,CAAC;AAIF,SAAS,eAAe,CACpB,UAAsD,EAAE,EACxD,UAAqC,EAAE,EACvC,iBAAmD,EAAE;IAGvD,OAAO,CAAC,GAAmC,EAAE,EAAE;QAE7C,KAAK,IAAI,IAAI,IAAI,OAAO,EAAE;YACxB,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;YACzB,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAU,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;SACnE;QAED,OAAO,CAAC,aAAmB,EAAC,EAAE;YAC5B,OAAO;gBACL,GAAG,YAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,CAC1C,aAAa,CAAC,IAAI,EAAC,MAAoB,CAAC,CAC3C;gBACD,GAAG,cAAc;aAClB;iBACE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;iBACd,WAAW,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,CAAC;QAC7D,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED,kBAAe,eAAe,CAAC"}
|
|
@ -1,5 +0,0 @@
|
|||
/// <reference types="lodash" />
|
||||
import { Mutation, Action, Dictionary } from '../types';
|
||||
declare function buildMutations(mutations?: Dictionary<Mutation>, subduxes?: {}): import("lodash").Dictionary<Mutation<any, Action<string, any>>>;
|
||||
export default buildMutations;
|
||||
//# sourceMappingURL=index.d.ts.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/buildMutations/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAWtD,iBAAS,cAAc,CACnB,SAAS,GAAE,UAAU,CAAC,QAAQ,CAAM,EACpC,QAAQ,KAAK,mEAgDhB;AAED,eAAe,cAAc,CAAC"}
|
|
@ -1,33 +0,0 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fp_1 = __importDefault(require("lodash/fp"));
|
||||
const updeep_1 = __importDefault(require("updeep"));
|
||||
const composeMutations = (mutations) => mutations.reduce((m1, m2) => (payload = null, action) => state => m2(payload, action)(m1(payload, action)(state)));
|
||||
function buildMutations(mutations = {}, subduxes = {}) {
|
||||
const actions = fp_1.default.uniq(Object.keys(mutations).concat(...Object.values(subduxes).map(({ mutations = {} }) => Object.keys(mutations))));
|
||||
let mergedMutations = {};
|
||||
let [globby, nonGlobby] = fp_1.default.partition(([_, { mutations = {} }]) => mutations['*'], Object.entries(subduxes));
|
||||
globby = fp_1.default.flow([
|
||||
fp_1.default.fromPairs,
|
||||
fp_1.default.mapValues(({ reducer }) => (_, action) => (state) => reducer(state, action)),
|
||||
])(globby);
|
||||
const globbyMutation = (payload, action) => updeep_1.default(fp_1.default.mapValues((mut) => mut(payload, action))(globby));
|
||||
actions.forEach(action => {
|
||||
mergedMutations[action] = [globbyMutation];
|
||||
});
|
||||
nonGlobby.forEach(([slice, { mutations = {}, reducer = {} }]) => {
|
||||
Object.entries(mutations).forEach(([type, mutation]) => {
|
||||
const localized = (payload = null, action) => updeep_1.default.updateIn(slice)(mutation(payload, action));
|
||||
mergedMutations[type].push(localized);
|
||||
});
|
||||
});
|
||||
Object.entries(mutations).forEach(([type, mutation]) => {
|
||||
mergedMutations[type].push(mutation);
|
||||
});
|
||||
return fp_1.default.mapValues(composeMutations)(mergedMutations);
|
||||
}
|
||||
exports.default = buildMutations;
|
||||
//# sourceMappingURL=index.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/buildMutations/index.ts"],"names":[],"mappings":"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"}
|
|
@ -1,2 +0,0 @@
|
|||
export {};
|
||||
//# sourceMappingURL=test.d.ts.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../src/buildMutations/test.ts"],"names":[],"mappings":""}
|
|
@ -1,13 +0,0 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const _1 = __importDefault(require("."));
|
||||
const actions = {
|
||||
multiply: (factor) => ({ factor }),
|
||||
};
|
||||
const mutations = _1.default({
|
||||
multiply: ({ factor }) => ({ counter }) => factor * counter,
|
||||
});
|
||||
//# sourceMappingURL=test.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/buildMutations/test.ts"],"names":[],"mappings":";;;;;AAAA,yCAA+B;AAE/B,MAAM,OAAO,GAAG;IACZ,QAAQ,EAAE,CAAC,MAAc,EAAE,EAAE,CAAC,CAAC,EAAC,MAAM,EAAC,CAAC;CAC3C,CAAC;AAEF,MAAM,SAAS,GAAG,UAAc,CAC5B;IACI,QAAQ,EAAE,CAAC,EAAC,MAAM,EAAC,EAAE,EAAE,CAAC,CAAC,EAAC,OAAO,EAAC,EAAE,EAAE,CAAC,MAAM,GAAG,OAAO;CAC1D,CACJ,CAAC"}
|
|
@ -1,4 +0,0 @@
|
|||
import { Dictionary, Mutation, Upreducer } from '../types';
|
||||
declare function buildUpreducer<S>(initial: S, mutations: Dictionary<Mutation<S>>): Upreducer<S>;
|
||||
export default buildUpreducer;
|
||||
//# sourceMappingURL=index.d.ts.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/buildUpreducer/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAU,SAAS,EAAE,MAAM,UAAU,CAAC;AAEnE,iBAAS,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAI,SAAS,CAAC,CAAC,CAAC,CAYxF;AAED,eAAe,cAAc,CAAC"}
|
|
@ -1,15 +0,0 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
function buildUpreducer(initial, mutations) {
|
||||
return (action) => (state) => {
|
||||
if (state === undefined)
|
||||
state = initial;
|
||||
const a = mutations[action.type] ||
|
||||
mutations['*'];
|
||||
if (!a)
|
||||
return state;
|
||||
return a(action.payload, action)(state);
|
||||
};
|
||||
}
|
||||
exports.default = buildUpreducer;
|
||||
//# sourceMappingURL=index.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/buildUpreducer/index.ts"],"names":[],"mappings":";;AAIA,SAAS,cAAc,CAAI,OAAU,EAAE,SAAkC;IACvE,OAAO,CAAC,MAAc,EAAE,EAAE,CAAC,CAAC,KAAQ,EAAE,EAAE;QACtC,IAAI,KAAK,KAAK,SAAS;YAAE,KAAK,GAAG,OAAO,CAAC;QAEzC,MAAM,CAAC,GACL,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;YACtB,SAAS,CAAC,GAAG,CAAC,CAAC;QAEjB,IAAG,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;QAEpB,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC,CAAC;AACJ,CAAC;AAED,kBAAe,cAAc,CAAC"}
|
|
@ -1,5 +0,0 @@
|
|||
import Updux from './updux';
|
||||
export { default as Updux } from './updux';
|
||||
export { UpduxConfig } from './types';
|
||||
export default Updux;
|
||||
//# sourceMappingURL=index.d.ts.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAC;AAE5B,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EACH,WAAW,EACd,MAAM,SAAS,CAAC;AAEjB,eAAe,KAAK,CAAC"}
|
|
@ -1,10 +0,0 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const updux_1 = __importDefault(require("./updux"));
|
||||
var updux_2 = require("./updux");
|
||||
exports.Updux = updux_2.default;
|
||||
exports.default = updux_1.default;
|
||||
//# sourceMappingURL=index.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAE5B,iCAA2C;AAAlC,wBAAA,OAAO,CAAS;AAKzB,kBAAe,eAAK,CAAC"}
|
|
@ -1,2 +0,0 @@
|
|||
export {};
|
||||
//# sourceMappingURL=middleware.test.d.ts.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"middleware.test.d.ts","sourceRoot":"","sources":["../src/middleware.test.ts"],"names":[],"mappings":""}
|
|
@ -1,81 +0,0 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const _1 = __importDefault(require("."));
|
||||
test('simple effect', () => {
|
||||
const tracer = jest.fn();
|
||||
const store = (new _1.default({
|
||||
effects: {
|
||||
foo: (api) => (next) => (action) => {
|
||||
tracer();
|
||||
next(action);
|
||||
},
|
||||
},
|
||||
})).createStore();
|
||||
expect(tracer).not.toHaveBeenCalled();
|
||||
store.dispatch({ type: 'bar' });
|
||||
expect(tracer).not.toHaveBeenCalled();
|
||||
store.dispatch.foo();
|
||||
expect(tracer).toHaveBeenCalled();
|
||||
});
|
||||
test('effect and sub-effect', () => {
|
||||
const tracer = jest.fn();
|
||||
const tracerEffect = (signature) => (api) => (next) => (action) => {
|
||||
tracer(signature);
|
||||
next(action);
|
||||
};
|
||||
const store = (new _1.default({
|
||||
effects: {
|
||||
foo: tracerEffect('root'),
|
||||
},
|
||||
subduxes: {
|
||||
zzz: { effects: {
|
||||
foo: tracerEffect('child'),
|
||||
}
|
||||
}
|
||||
},
|
||||
})).createStore();
|
||||
expect(tracer).not.toHaveBeenCalled();
|
||||
store.dispatch({ type: 'bar' });
|
||||
expect(tracer).not.toHaveBeenCalled();
|
||||
store.dispatch.foo();
|
||||
expect(tracer).toHaveBeenNthCalledWith(1, 'root');
|
||||
expect(tracer).toHaveBeenNthCalledWith(2, 'child');
|
||||
});
|
||||
test('"*" effect', () => {
|
||||
const tracer = jest.fn();
|
||||
const store = (new _1.default({
|
||||
effects: {
|
||||
'*': api => next => action => {
|
||||
tracer();
|
||||
next(action);
|
||||
},
|
||||
},
|
||||
})).createStore();
|
||||
expect(tracer).not.toHaveBeenCalled();
|
||||
store.dispatch({ type: 'bar' });
|
||||
expect(tracer).toHaveBeenCalled();
|
||||
});
|
||||
test('async effect', async () => {
|
||||
function timeout(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
const tracer = jest.fn();
|
||||
const store = (new _1.default({
|
||||
effects: {
|
||||
foo: api => next => async (action) => {
|
||||
next(action);
|
||||
await timeout(1000);
|
||||
tracer();
|
||||
},
|
||||
},
|
||||
})).createStore();
|
||||
expect(tracer).not.toHaveBeenCalled();
|
||||
store.dispatch.foo();
|
||||
expect(tracer).not.toHaveBeenCalled();
|
||||
await timeout(1000);
|
||||
expect(tracer).toHaveBeenCalled();
|
||||
});
|
||||
//# sourceMappingURL=middleware.test.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"middleware.test.js","sourceRoot":"","sources":["../src/middleware.test.ts"],"names":[],"mappings":"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"}
|
|
@ -1,2 +0,0 @@
|
|||
export {};
|
||||
//# sourceMappingURL=splat.test.d.ts.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"splat.test.d.ts","sourceRoot":"","sources":["../src/splat.test.ts"],"names":[],"mappings":""}
|
|
@ -1,55 +0,0 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const _1 = __importDefault(require("."));
|
||||
const updeep_1 = __importDefault(require("updeep"));
|
||||
const tracer = (chr) => updeep_1.default({ tracer: (s = '') => s + chr });
|
||||
test('mutations, simple', () => {
|
||||
const dux = new _1.default({
|
||||
mutations: {
|
||||
foo: () => tracer('a'),
|
||||
'*': () => tracer('b'),
|
||||
},
|
||||
});
|
||||
const store = dux.createStore();
|
||||
expect(store.getState()).toEqual({ tracer: 'b' });
|
||||
store.dispatch.foo();
|
||||
expect(store.getState()).toEqual({ tracer: 'ba', });
|
||||
store.dispatch({ type: 'bar' });
|
||||
expect(store.getState()).toEqual({ tracer: 'bab', });
|
||||
});
|
||||
test('with subduxes', () => {
|
||||
const dux = new _1.default({
|
||||
mutations: {
|
||||
foo: () => tracer('a'),
|
||||
'*': () => tracer('b'),
|
||||
bar: () => ({ bar }) => ({ bar, tracer: bar.tracer })
|
||||
},
|
||||
subduxes: {
|
||||
bar: {
|
||||
mutations: {
|
||||
foo: () => tracer('d'),
|
||||
'*': () => tracer('e'),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const store = dux.createStore();
|
||||
expect(store.getState()).toEqual({
|
||||
tracer: 'b',
|
||||
bar: { tracer: 'e' }
|
||||
});
|
||||
store.dispatch.foo();
|
||||
expect(store.getState()).toEqual({
|
||||
tracer: 'ba',
|
||||
bar: { tracer: 'ed' }
|
||||
});
|
||||
store.dispatch({ type: 'bar' });
|
||||
expect(store.getState()).toEqual({
|
||||
tracer: 'ede',
|
||||
bar: { tracer: 'ede' }
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=splat.test.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"splat.test.js","sourceRoot":"","sources":["../src/splat.test.ts"],"names":[],"mappings":";;;;;AAAA,yCAAsB;AACtB,oDAAuB;AAEvB,MAAM,MAAM,GAAG,CAAC,GAAU,EAAE,EAAE,CAAC,gBAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,GAAC,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;AAEhE,IAAI,CAAE,mBAAmB,EAAE,GAAG,EAAE;IAC5B,MAAM,GAAG,GAAG,IAAI,UAAK,CAAC;QAClB,SAAS,EAAE;YACP,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC;YACtB,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC;SACzB;KACJ,CAAC,CAAC;IAEJ,MAAM,KAAK,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;IAE/B,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,EAAC,CAAC,CAAC;IAEjD,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;IAErB,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,GAAG,CAAC,CAAC;IAEpD,KAAK,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAEhC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,GAAG,CAAC,CAAC;AACzD,CAAC,CAAC,CAAC;AAEH,IAAI,CAAE,eAAe,EAAE,GAAG,EAAE;IACxB,MAAM,GAAG,GAAG,IAAI,UAAK,CAAC;QAClB,SAAS,EAAE;YACP,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC;YACtB,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC;YACtB,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,EAAC,GAAG,EAAK,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC;SAC1D;QACD,QAAQ,EAAE;YACN,GAAG,EAAE;gBACD,SAAS,EAAE;oBACP,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC;oBAClB,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC;iBAC7B;aACJ;SACJ;KACJ,CAAC,CAAC;IAEJ,MAAM,KAAK,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;IAE/B,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC;QAC7B,MAAM,EAAE,GAAG;QACX,GAAG,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE;KAAE,CAAC,CAAC;IAE5B,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;IAErB,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC;QAC7B,MAAM,EAAE,IAAI;QACZ,GAAG,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;KAAE,CAAC,CAAC;IAE7B,KAAK,CAAC,QAAQ,CAAC,EAAC,IAAI,EAAE,KAAK,EAAC,CAAC,CAAC;IAE9B,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC;QAC7B,MAAM,EAAE,KAAK;QACb,GAAG,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE;KAAE,CAAC,CAAC;AAGlC,CAAC,CAAC,CAAC"}
|
|
@ -1,2 +0,0 @@
|
|||
export {};
|
||||
//# sourceMappingURL=test.d.ts.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":""}
|
|
@ -1,153 +0,0 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const _1 = __importDefault(require("."));
|
||||
test('actions from mutations', () => {
|
||||
const { actions: { foo, bar }, } = new _1.default({
|
||||
mutations: {
|
||||
foo: () => (x) => x,
|
||||
},
|
||||
});
|
||||
expect(foo()).toEqual({ type: 'foo' });
|
||||
expect(foo(true)).toEqual({ type: 'foo', payload: true });
|
||||
expect(foo({ bar: 2 }, { timestamp: 613 })).toEqual({
|
||||
type: 'foo',
|
||||
payload: { bar: 2 },
|
||||
meta: { timestamp: 613 },
|
||||
});
|
||||
});
|
||||
test('reducer', () => {
|
||||
const { actions, reducer } = new _1.default({
|
||||
initial: { counter: 1 },
|
||||
mutations: {
|
||||
inc: () => ({ counter }) => ({ counter: counter + 1 }),
|
||||
},
|
||||
});
|
||||
let state = reducer(undefined, { type: 'noop' });
|
||||
expect(state).toEqual({ counter: 1 });
|
||||
state = reducer(state, actions.inc());
|
||||
expect(state).toEqual({ counter: 2 });
|
||||
});
|
||||
test('sub reducers', () => {
|
||||
const foo = new _1.default({
|
||||
initial: 1,
|
||||
mutations: {
|
||||
doFoo: () => (x) => x + 1,
|
||||
doAll: () => (x) => x + 10,
|
||||
},
|
||||
});
|
||||
const bar = new _1.default({
|
||||
initial: 'a',
|
||||
mutations: {
|
||||
doBar: () => (x) => x + 'a',
|
||||
doAll: () => (x) => x + 'b',
|
||||
}
|
||||
});
|
||||
const { initial, actions, reducer } = new _1.default({
|
||||
subduxes: {
|
||||
foo, bar
|
||||
}
|
||||
});
|
||||
expect(initial).toEqual({ foo: 1, bar: 'a' });
|
||||
expect(Object.keys(actions)).toHaveLength(3);
|
||||
let state = reducer(undefined, { type: 'noop' });
|
||||
expect(state).toEqual({ foo: 1, bar: 'a' });
|
||||
state = reducer(state, actions.doFoo());
|
||||
expect(state).toEqual({ foo: 2, bar: 'a' });
|
||||
state = reducer(state, actions.doBar());
|
||||
expect(state).toEqual({ foo: 2, bar: 'aa' });
|
||||
state = reducer(state, actions.doAll());
|
||||
expect(state).toEqual({ foo: 12, bar: 'aab' });
|
||||
});
|
||||
test('precedence between root and sub-reducers', () => {
|
||||
const { initial, reducer, actions, } = new _1.default({
|
||||
initial: {
|
||||
foo: { bar: 4 },
|
||||
},
|
||||
mutations: {
|
||||
inc: () => (state) => {
|
||||
return {
|
||||
...state,
|
||||
surprise: state.foo.bar
|
||||
};
|
||||
}
|
||||
},
|
||||
subduxes: {
|
||||
foo: {
|
||||
initial: {
|
||||
bar: 2,
|
||||
quux: 3,
|
||||
},
|
||||
mutations: {
|
||||
inc: () => (state) => ({ ...state, bar: state.bar + 1 })
|
||||
},
|
||||
},
|
||||
}
|
||||
});
|
||||
expect(initial).toEqual({
|
||||
foo: { bar: 4, quux: 3 }
|
||||
});
|
||||
expect(reducer(undefined, actions.inc())).toEqual({
|
||||
foo: { bar: 5, quux: 3 }, surprise: 5
|
||||
});
|
||||
});
|
||||
function timeout(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
test('middleware', async () => {
|
||||
const { middleware, createStore } = new _1.default({
|
||||
initial: "",
|
||||
mutations: {
|
||||
inc: (addition) => (state) => state + addition,
|
||||
doEeet: () => (state) => {
|
||||
return state + 'Z';
|
||||
},
|
||||
},
|
||||
effects: {
|
||||
doEeet: api => next => async (action) => {
|
||||
api.dispatch.inc('a');
|
||||
next(action);
|
||||
await timeout(1000);
|
||||
api.dispatch.inc('c');
|
||||
}
|
||||
},
|
||||
subduxes: {
|
||||
foo: {
|
||||
effects: {
|
||||
doEeet: (api) => (next) => (action) => {
|
||||
api.dispatch({ type: 'inc', payload: 'b' });
|
||||
next(action);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
const store = createStore();
|
||||
store.dispatch.doEeet();
|
||||
expect(store.getState()).toEqual('abZ');
|
||||
await timeout(1000);
|
||||
expect(store.getState()).toEqual('abZc');
|
||||
});
|
||||
test("subduxes and mutations", () => {
|
||||
const foo = new _1.default({ mutations: {
|
||||
quux: () => () => 'x',
|
||||
blart: () => () => 'a',
|
||||
} });
|
||||
const bar = new _1.default({ mutations: {
|
||||
quux: () => () => 'y'
|
||||
} });
|
||||
const baz = new _1.default({
|
||||
mutations: {
|
||||
quux: () => (state) => ({ ...state, "baz": "z" })
|
||||
}, subduxes: { foo, bar }
|
||||
});
|
||||
let state = baz.reducer(undefined, baz.actions.quux());
|
||||
expect(state).toEqual({
|
||||
foo: "x",
|
||||
bar: "y",
|
||||
baz: "z",
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=test.js.map
|
File diff suppressed because one or more lines are too long
|
@ -1,32 +0,0 @@
|
|||
import { Dispatch, Middleware } from 'redux';
|
||||
declare type MaybePayload<P> = P extends object | string | boolean | number ? {
|
||||
payload: P;
|
||||
} : {
|
||||
payload?: P;
|
||||
};
|
||||
export declare type Action<T extends string = string, P = any> = {
|
||||
type: T;
|
||||
} & MaybePayload<P>;
|
||||
export declare type Dictionary<T> = {
|
||||
[key: string]: T;
|
||||
};
|
||||
export declare type Mutation<S = any, A extends Action = Action> = (payload: A['payload'], action: A) => (state: S) => S;
|
||||
export declare type ActionPayloadGenerator = (...args: any[]) => any;
|
||||
export declare type ActionCreator<T extends string = string, P = any> = {
|
||||
type: T;
|
||||
_genericAction?: boolean;
|
||||
} & ((...args: any[]) => Action<T, P>);
|
||||
export declare type UpduxDispatch = Dispatch & Dictionary<Function>;
|
||||
export declare type UpduxConfig<S = any> = {
|
||||
initial?: S;
|
||||
subduxes?: {};
|
||||
actions?: {
|
||||
[type: string]: ActionCreator;
|
||||
};
|
||||
mutations?: any;
|
||||
groomMutations?: (m: Mutation<S>) => Mutation<S>;
|
||||
effects?: Dictionary<Middleware<{}, S, UpduxDispatch>>;
|
||||
};
|
||||
export declare type Upreducer<S = any> = (action: Action) => (state: S) => S;
|
||||
export {};
|
||||
//# sourceMappingURL=types.d.ts.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,UAAU,EAAC,MAAM,OAAO,CAAC;AAE3C,aAAK,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAC/D;IACE,OAAO,EAAE,CAAC,CAAC;CACZ,GACD;IAAC,OAAO,CAAC,EAAE,CAAC,CAAA;CAAC,CAAC;AAElB,oBAAY,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,GAAG,IAAI;IACvD,IAAI,EAAE,CAAC,CAAC;CACT,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;AAEpB,oBAAY,UAAU,CAAC,CAAC,IAAI;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAA;CAAC,CAAC;AAE/C,oBAAY,QAAQ,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,CACzD,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,EACrB,MAAM,EAAE,CAAC,KACN,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;AAErB,oBAAY,sBAAsB,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAE7D,oBAAY,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,GAAG,IAAI;IAC9D,IAAI,EAAE,CAAC,CAAC;IACR,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAEvC,oBAAY,aAAa,GAAG,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;AAO5D,oBAAY,WAAW,CAAC,CAAC,GAAC,GAAG,IAAI;IAK/B,OAAO,CAAC,EAAE,CAAC,CAAC;IA+BZ,QAAQ,CAAC,EAAE,EAAE,CAAC;IAsBd,OAAO,CAAC,EAAE;QACR,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAAC;KAC/B,CAAC;IAgEF,SAAS,CAAC,EAAE,GAAG,CAAC;IAEhB,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC;IAqBjD,OAAO,CAAC,EAAE,UAAU,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC;CACxD,CAAC;AAEF,oBAAY,SAAS,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC"}
|
|
@ -1,3 +0,0 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=types.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@ -1,30 +0,0 @@
|
|||
import { UpduxConfig, Dictionary, Action, ActionCreator, Mutation, Upreducer, UpduxDispatch } from './types';
|
||||
import { Middleware, Store } from 'redux';
|
||||
export { actionCreator } from './buildActions';
|
||||
declare type StoreWithDispatchActions<S = any, Actions = {
|
||||
[action: string]: (...args: any) => Action;
|
||||
}> = Store<S> & {
|
||||
dispatch: {
|
||||
[type in keyof Actions]: (...args: any) => void;
|
||||
};
|
||||
};
|
||||
export declare type Dux<S> = Pick<Updux<S>, 'subduxes' | 'actions' | 'initial' | 'mutations' | 'reducer' | 'middleware' | 'createStore' | 'upreducer'>;
|
||||
export declare class Updux<S = any> {
|
||||
subduxes: Dictionary<Updux>;
|
||||
initial: S;
|
||||
groomMutations: (mutation: Mutation<S>) => Mutation<S>;
|
||||
private localEffects;
|
||||
private localActions;
|
||||
private localMutations;
|
||||
constructor(config?: UpduxConfig);
|
||||
readonly middleware: Middleware<{}, S, UpduxDispatch>;
|
||||
readonly actions: Dictionary<ActionCreator>;
|
||||
readonly upreducer: Upreducer<S>;
|
||||
readonly reducer: (state: S | undefined, action: Action) => S;
|
||||
readonly mutations: Dictionary<Mutation<S>>;
|
||||
readonly createStore: () => StoreWithDispatchActions<S>;
|
||||
readonly asDux: Dux<S>;
|
||||
addMutation<A extends ActionCreator>(creator: A, mutation: Mutation<S, A extends (...args: any[]) => infer R ? R : never>): void;
|
||||
}
|
||||
export default Updux;
|
||||
//# sourceMappingURL=updux.d.ts.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"updux.d.ts","sourceRoot":"","sources":["../src/updux.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,WAAW,EACX,UAAU,EACV,MAAM,EACN,aAAa,EACb,QAAQ,EACR,SAAS,EACT,aAAa,EACd,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAC,UAAU,EAAE,KAAK,EAAC,MAAM,OAAO,CAAC;AACxC,OAAO,EAAC,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAE7C,aAAK,wBAAwB,CAC3B,CAAC,GAAG,GAAG,EACP,OAAO,GAAG;IAAC,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,MAAM,CAAA;CAAC,IACpD,KAAK,CAAC,CAAC,CAAC,GAAG;IACb,QAAQ,EAAE;SAAE,IAAI,IAAI,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,IAAI;KAAC,CAAC;CAC7D,CAAC;AAEF,oBAAY,GAAG,CAAC,CAAC,IAAI,IAAI,CACvB,KAAK,CAAC,CAAC,CAAC,EACN,UAAU,GACV,SAAS,GACT,SAAS,GACT,WAAW,GACX,SAAS,GACT,YAAY,GACZ,aAAa,GACb,WAAW,CACd,CAAC;AASF,qBAAa,KAAK,CAAC,CAAC,GAAG,GAAG;IACxB,QAAQ,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IAS5B,OAAO,EAAE,CAAC,CAAC;IAqCX,cAAc,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE3C,OAAO,CAAC,YAAY,CAE9B;IAEU,OAAO,CAAC,YAAY,CAA4B;IAEhD,OAAO,CAAC,cAAc,CAA0B;gBAEhD,MAAM,GAAE,WAAgB;aA0BtB,UAAU,EAAI,UAAU,CAAC,EAAE,EAAE,CAAC,EAAE,aAAa,CAAC;aAsB9C,OAAO,EAAI,UAAU,CAAC,aAAa,CAAC;aAYpC,SAAS,EAAI,SAAS,CAAC,CAAC,CAAC;aAQzB,OAAO,EAAI,CAAC,KAAK,EAAE,CAAC,GAAG,SAAS,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;aAStD,SAAS,EAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;aA6BpC,WAAW,EAAI,MAAM,wBAAwB,CAAC,CAAC,CAAC;aAiB1D,KAAK,EAAI,GAAG,CAAC,CAAC,CAAC;IAsBnB,WAAW,CAAC,CAAC,SAAS,aAAa,EACjC,OAAO,EAAE,CAAC,EACV,QAAQ,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;CAO3E;AAED,eAAe,KAAK,CAAC"}
|
|
@ -1,96 +0,0 @@
|
|||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fp_1 = __importDefault(require("lodash/fp"));
|
||||
const mobx_1 = require("mobx");
|
||||
const buildActions_1 = __importDefault(require("./buildActions"));
|
||||
const buildInitial_1 = __importDefault(require("./buildInitial"));
|
||||
const buildMutations_1 = __importDefault(require("./buildMutations"));
|
||||
const buildCreateStore_1 = __importDefault(require("./buildCreateStore"));
|
||||
const buildMiddleware_1 = __importDefault(require("./buildMiddleware"));
|
||||
const buildUpreducer_1 = __importDefault(require("./buildUpreducer"));
|
||||
var buildActions_2 = require("./buildActions");
|
||||
exports.actionCreator = buildActions_2.actionCreator;
|
||||
class Updux {
|
||||
constructor(config = {}) {
|
||||
this.groomMutations = config.groomMutations || ((x) => x);
|
||||
this.subduxes = fp_1.default.mapValues((value) => fp_1.default.isPlainObject(value) ? new Updux(value) : value)(fp_1.default.getOr({}, 'subduxes', config));
|
||||
this.localActions = fp_1.default.getOr({}, 'actions', config);
|
||||
this.localEffects = fp_1.default.getOr({}, 'effects', config);
|
||||
this.initial = buildInitial_1.default(config.initial, fp_1.default.mapValues(({ initial }) => initial)(this.subduxes));
|
||||
this.localMutations = fp_1.default.mapValues((m) => this.groomMutations(m))(fp_1.default.getOr({}, 'mutations', config));
|
||||
}
|
||||
get middleware() {
|
||||
return buildMiddleware_1.default(this.localEffects, this.actions, Object.values(this.subduxes).map(sd => sd.middleware));
|
||||
}
|
||||
get actions() {
|
||||
return buildActions_1.default(this.localActions, [...Object.keys(this.localMutations), ...Object.keys(this.localEffects)], fp_1.default.flatten(Object.values(this.subduxes).map(({ actions }) => Object.entries(actions))));
|
||||
}
|
||||
get upreducer() {
|
||||
return buildUpreducer_1.default(this.initial, this.mutations);
|
||||
}
|
||||
get reducer() {
|
||||
return (state, action) => this.upreducer(action)(state);
|
||||
}
|
||||
get mutations() {
|
||||
return buildMutations_1.default(this.localMutations, this.subduxes);
|
||||
}
|
||||
get createStore() {
|
||||
const actions = this.actions;
|
||||
return buildCreateStore_1.default(this.reducer, this.initial, this.middleware, this.actions);
|
||||
}
|
||||
get asDux() {
|
||||
return {
|
||||
createStore: this.createStore,
|
||||
upreducer: this.upreducer,
|
||||
subduxes: this.subduxes,
|
||||
middleware: this.middleware,
|
||||
actions: this.actions,
|
||||
reducer: this.reducer,
|
||||
mutations: this.mutations,
|
||||
initial: this.initial,
|
||||
};
|
||||
}
|
||||
addMutation(creator, mutation) {
|
||||
this.localActions[creator.type] = creator;
|
||||
this.localMutations[creator.type] = this.groomMutations(mutation);
|
||||
}
|
||||
}
|
||||
__decorate([
|
||||
mobx_1.observable
|
||||
], Updux.prototype, "localEffects", void 0);
|
||||
__decorate([
|
||||
mobx_1.observable
|
||||
], Updux.prototype, "localActions", void 0);
|
||||
__decorate([
|
||||
mobx_1.observable
|
||||
], Updux.prototype, "localMutations", void 0);
|
||||
__decorate([
|
||||
mobx_1.computed
|
||||
], Updux.prototype, "middleware", null);
|
||||
__decorate([
|
||||
mobx_1.computed
|
||||
], Updux.prototype, "actions", null);
|
||||
__decorate([
|
||||
mobx_1.computed
|
||||
], Updux.prototype, "upreducer", null);
|
||||
__decorate([
|
||||
mobx_1.computed
|
||||
], Updux.prototype, "reducer", null);
|
||||
__decorate([
|
||||
mobx_1.computed
|
||||
], Updux.prototype, "mutations", null);
|
||||
__decorate([
|
||||
mobx_1.computed
|
||||
], Updux.prototype, "createStore", null);
|
||||
exports.Updux = Updux;
|
||||
exports.default = Updux;
|
||||
//# sourceMappingURL=updux.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"updux.js","sourceRoot":"","sources":["../src/updux.ts"],"names":[],"mappings":"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"}
|
|
@ -0,0 +1,226 @@
|
|||
# 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/).
|
||||
Right now the best way to understand the whole thing is to go
|
||||
through the [tutorial](https://yanick.github.io/updux/#/tutorial)
|
||||
|
||||
## 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
|
||||
}
|
||||
});
|
||||
|
||||
```
|
|
@ -0,0 +1,3 @@
|
|||
* [Home](/)
|
||||
* [ Tutorial ](tutorial.md)
|
||||
* [ Recipes ](recipes.md)
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Before Width: | Height: | Size: 9.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 28 KiB |
Binary file not shown.
Before Width: | Height: | Size: 480 B |
Binary file not shown.
Before Width: | Height: | Size: 855 B |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,729 +0,0 @@
|
|||
<!doctype html>
|
||||
<html class="default no-js">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>Updux | updux</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="../assets/css/main.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<div class="tsd-page-toolbar">
|
||||
<div class="container">
|
||||
<div class="table-wrap">
|
||||
<div class="table-cell" id="tsd-search" data-index="../assets/js/search.js" data-base="..">
|
||||
<div class="field">
|
||||
<label for="tsd-search-field" class="tsd-widget search no-caption">Search</label>
|
||||
<input id="tsd-search-field" type="text" />
|
||||
</div>
|
||||
<ul class="results">
|
||||
<li class="state loading">Preparing search index...</li>
|
||||
<li class="state failure">The search index is not available</li>
|
||||
</ul>
|
||||
<a href="../index.html" class="title">updux</a>
|
||||
</div>
|
||||
<div class="table-cell" id="tsd-widgets">
|
||||
<div id="tsd-filter">
|
||||
<a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a>
|
||||
<div class="tsd-filter-group">
|
||||
<div class="tsd-select" id="tsd-filter-visibility">
|
||||
<span class="tsd-select-label">All</span>
|
||||
<ul class="tsd-select-list">
|
||||
<li data-value="public">Public</li>
|
||||
<li data-value="protected">Public/Protected</li>
|
||||
<li data-value="private" class="selected">All</li>
|
||||
</ul>
|
||||
</div>
|
||||
<input type="checkbox" id="tsd-filter-inherited" checked />
|
||||
<label class="tsd-widget" for="tsd-filter-inherited">Inherited</label>
|
||||
<input type="checkbox" id="tsd-filter-externals" checked />
|
||||
<label class="tsd-widget" for="tsd-filter-externals">Externals</label>
|
||||
<input type="checkbox" id="tsd-filter-only-exported" />
|
||||
<label class="tsd-widget" for="tsd-filter-only-exported">Only exported</label>
|
||||
</div>
|
||||
</div>
|
||||
<a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tsd-page-title">
|
||||
<div class="container">
|
||||
<ul class="tsd-breadcrumb">
|
||||
<li>
|
||||
<a href="../globals.html">Globals</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="updux.html">Updux</a>
|
||||
</li>
|
||||
</ul>
|
||||
<h1>Class Updux<S></h1>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div class="container container-main">
|
||||
<div class="row">
|
||||
<div class="col-8 col-content">
|
||||
<section class="tsd-panel tsd-comment">
|
||||
<div class="tsd-comment tsd-typography">
|
||||
<div class="lead">
|
||||
<p><code>Updux</code> is a way to minimize and simplify the boilerplate associated with the
|
||||
creation of a <code>Redux</code> store. It takes a shorthand configuration
|
||||
object, and generates the appropriate reducer, actions, middleware, etc.
|
||||
In true <code>Redux</code>-like fashion, upduxes can be made of sub-upduxes (<code>subduxes</code> for short) for different slices of the root state.</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section class="tsd-panel tsd-type-parameters">
|
||||
<h3>Type parameters</h3>
|
||||
<ul class="tsd-type-parameters">
|
||||
<li>
|
||||
<h4>S</h4>
|
||||
<div class="tsd-comment tsd-typography">
|
||||
<div class="lead">
|
||||
<p>Store's state type. Defaults to <code>any</code>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="tsd-panel tsd-hierarchy">
|
||||
<h3>Hierarchy</h3>
|
||||
<ul class="tsd-hierarchy">
|
||||
<li>
|
||||
<span class="target">Updux</span>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="tsd-panel-group tsd-index-group">
|
||||
<h2>Index</h2>
|
||||
<section class="tsd-panel tsd-index-panel">
|
||||
<div class="tsd-index-content">
|
||||
<section class="tsd-index-section ">
|
||||
<h3>Constructors</h3>
|
||||
<ul class="tsd-index-list">
|
||||
<li class="tsd-kind-constructor tsd-parent-kind-class"><a href="updux.html#constructor" class="tsd-kind-icon">constructor</a></li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="tsd-index-section ">
|
||||
<h3>Properties</h3>
|
||||
<ul class="tsd-index-list">
|
||||
<li class="tsd-kind-property tsd-parent-kind-class"><a href="updux.html#groommutations" class="tsd-kind-icon">groom<wbr>Mutations</a></li>
|
||||
<li class="tsd-kind-property tsd-parent-kind-class"><a href="updux.html#initial" class="tsd-kind-icon">initial</a></li>
|
||||
<li class="tsd-kind-property tsd-parent-kind-class"><a href="updux.html#subduxes" class="tsd-kind-icon">subduxes</a></li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="tsd-index-section ">
|
||||
<h3>Accessors</h3>
|
||||
<ul class="tsd-index-list">
|
||||
<li class="tsd-kind-get-signature tsd-parent-kind-class"><a href="updux.html#actions" class="tsd-kind-icon">actions</a></li>
|
||||
<li class="tsd-kind-get-signature tsd-parent-kind-class"><a href="updux.html#asdux" class="tsd-kind-icon">as<wbr>Dux</a></li>
|
||||
<li class="tsd-kind-get-signature tsd-parent-kind-class"><a href="updux.html#createstore" class="tsd-kind-icon">create<wbr>Store</a></li>
|
||||
<li class="tsd-kind-get-signature tsd-parent-kind-class"><a href="updux.html#middleware" class="tsd-kind-icon">middleware</a></li>
|
||||
<li class="tsd-kind-get-signature tsd-parent-kind-class"><a href="updux.html#mutations" class="tsd-kind-icon">mutations</a></li>
|
||||
<li class="tsd-kind-get-signature tsd-parent-kind-class"><a href="updux.html#reducer" class="tsd-kind-icon">reducer</a></li>
|
||||
<li class="tsd-kind-get-signature tsd-parent-kind-class"><a href="updux.html#upreducer" class="tsd-kind-icon">upreducer</a></li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="tsd-index-section ">
|
||||
<h3>Methods</h3>
|
||||
<ul class="tsd-index-list">
|
||||
<li class="tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter"><a href="updux.html#addmutation" class="tsd-kind-icon">add<wbr>Mutation</a></li>
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
<section class="tsd-panel-group tsd-member-group ">
|
||||
<h2>Constructors</h2>
|
||||
<section class="tsd-panel tsd-member tsd-kind-constructor tsd-parent-kind-class">
|
||||
<a name="constructor" class="tsd-anchor"></a>
|
||||
<h3>constructor</h3>
|
||||
<ul class="tsd-signatures tsd-kind-constructor tsd-parent-kind-class">
|
||||
<li class="tsd-signature tsd-kind-icon">new <wbr>Updux<span class="tsd-signature-symbol">(</span>config<span class="tsd-signature-symbol">?: </span><a href="../globals.html#upduxconfig" class="tsd-signature-type">UpduxConfig</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="updux.html" class="tsd-signature-type">Updux</a></li>
|
||||
</ul>
|
||||
<ul class="tsd-descriptions">
|
||||
<li class="tsd-description">
|
||||
<aside class="tsd-sources">
|
||||
<ul>
|
||||
<li>Defined in updux.ts:106</li>
|
||||
</ul>
|
||||
</aside>
|
||||
<h4 class="tsd-parameters-title">Parameters</h4>
|
||||
<ul class="tsd-parameters">
|
||||
<li>
|
||||
<h5><span class="tsd-flag ts-flagDefault value">Default value</span> config: <a href="../globals.html#upduxconfig" class="tsd-signature-type">UpduxConfig</a><span class="tsd-signature-symbol"> = {}</span></h5>
|
||||
</li>
|
||||
</ul>
|
||||
<h4 class="tsd-returns-title">Returns <a href="updux.html" class="tsd-signature-type">Updux</a></h4>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
</section>
|
||||
<section class="tsd-panel-group tsd-member-group ">
|
||||
<h2>Properties</h2>
|
||||
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
|
||||
<a name="groommutations" class="tsd-anchor"></a>
|
||||
<h3>groom<wbr>Mutations</h3>
|
||||
<div class="tsd-signature tsd-kind-icon">groom<wbr>Mutations<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">function</span></div>
|
||||
<aside class="tsd-sources">
|
||||
<ul>
|
||||
<li>Defined in updux.ts:98</li>
|
||||
</ul>
|
||||
</aside>
|
||||
<div class="tsd-comment tsd-typography">
|
||||
<div class="lead">
|
||||
<p>Function that can be provided to alter all local mutations of the updux
|
||||
(the mutations of subduxes are left untouched).</p>
|
||||
</div>
|
||||
<p>Can be used, for example, for Immer integration:</p>
|
||||
<pre><code><span class="hljs-keyword">import</span> Updux <span class="hljs-keyword">from</span> <span class="hljs-string">'updux'</span>;
|
||||
<span class="hljs-keyword">import</span> { produce } <span class="hljs-keyword">from</span> <span class="hljs-string">'Immer'</span>;
|
||||
|
||||
<span class="hljs-keyword">const</span> updux = <span class="hljs-keyword">new</span> Updux({
|
||||
<span class="hljs-attr">initial</span>: { <span class="hljs-attr">counter</span>: <span class="hljs-number">0</span> },
|
||||
<span class="hljs-attr">groomMutations</span>: <span class="hljs-function"><span class="hljs-params">mutation</span> =></span> <span class="hljs-function">(<span class="hljs-params">...args</span>) =></span> produce( mutation(...args) ),
|
||||
<span class="hljs-attr">mutations</span>: {
|
||||
<span class="hljs-attr">add</span>: <span class="hljs-function">(<span class="hljs-params">inc=<span class="hljs-number">1</span></span>) =></span> <span class="hljs-function"><span class="hljs-params">draft</span> =></span> draft.counter += inc
|
||||
}
|
||||
});
|
||||
</code></pre><p>Or perhaps for debugging:</p>
|
||||
<pre><code><span class="hljs-keyword">import</span> Updux <span class="hljs-keyword">from</span> <span class="hljs-string">'updux'</span>;
|
||||
|
||||
<span class="hljs-keyword">const</span> updux = <span class="hljs-keyword">new</span> Updux({
|
||||
<span class="hljs-attr">initial</span>: { <span class="hljs-attr">counter</span>: <span class="hljs-number">0</span> },
|
||||
<span class="hljs-attr">groomMutations</span>: <span class="hljs-function"><span class="hljs-params">mutation</span> =></span> <span class="hljs-function">(<span class="hljs-params">...args</span>) =></span> <span class="hljs-function"><span class="hljs-params">state</span> =></span> {
|
||||
<span class="hljs-built_in">console</span>.log( <span class="hljs-string">"got action "</span>, args[<span class="hljs-number">1</span>] );
|
||||
<span class="hljs-keyword">return</span> mutation(...args)(state);
|
||||
}
|
||||
});
|
||||
</code></pre>
|
||||
</div>
|
||||
<div class="tsd-type-declaration">
|
||||
<h4>Type declaration</h4>
|
||||
<ul class="tsd-parameters">
|
||||
<li class="tsd-parameter-siganture">
|
||||
<ul class="tsd-signatures tsd-kind-type-literal tsd-parent-kind-property">
|
||||
<li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">(</span>mutation<span class="tsd-signature-symbol">: </span><a href="../globals.html#mutation" class="tsd-signature-type">Mutation</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../globals.html#mutation" class="tsd-signature-type">Mutation</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">></span></li>
|
||||
</ul>
|
||||
<ul class="tsd-descriptions">
|
||||
<li class="tsd-description">
|
||||
<h4 class="tsd-parameters-title">Parameters</h4>
|
||||
<ul class="tsd-parameters">
|
||||
<li>
|
||||
<h5>mutation: <a href="../globals.html#mutation" class="tsd-signature-type">Mutation</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">></span></h5>
|
||||
</li>
|
||||
</ul>
|
||||
<h4 class="tsd-returns-title">Returns <a href="../globals.html#mutation" class="tsd-signature-type">Mutation</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">></span></h4>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
|
||||
<a name="initial" class="tsd-anchor"></a>
|
||||
<h3>initial</h3>
|
||||
<div class="tsd-signature tsd-kind-icon">initial<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">S</span></div>
|
||||
<aside class="tsd-sources">
|
||||
<ul>
|
||||
<li>Defined in updux.ts:61</li>
|
||||
</ul>
|
||||
</aside>
|
||||
<div class="tsd-comment tsd-typography">
|
||||
<div class="lead">
|
||||
<p>Default initial state of the reducer. If applicable, merges the
|
||||
initial states of <code>config</code> and <code>subduxes</code>, with <code>config</code> having
|
||||
precedence.</p>
|
||||
</div>
|
||||
<p>If nothing was provided, defaults to an empty object.</p>
|
||||
</div>
|
||||
</section>
|
||||
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
|
||||
<a name="subduxes" class="tsd-anchor"></a>
|
||||
<h3>subduxes</h3>
|
||||
<div class="tsd-signature tsd-kind-icon">subduxes<span class="tsd-signature-symbol">:</span> <a href="../globals.html#dictionary" class="tsd-signature-type">Dictionary</a><span class="tsd-signature-symbol"><</span><a href="updux.html" class="tsd-signature-type">Updux</a><span class="tsd-signature-symbol">></span></div>
|
||||
<aside class="tsd-sources">
|
||||
<ul>
|
||||
<li>Defined in updux.ts:52</li>
|
||||
</ul>
|
||||
</aside>
|
||||
</section>
|
||||
</section>
|
||||
<section class="tsd-panel-group tsd-member-group ">
|
||||
<h2>Accessors</h2>
|
||||
<section class="tsd-panel tsd-member tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<a name="actions" class="tsd-anchor"></a>
|
||||
<h3>actions</h3>
|
||||
<ul class="tsd-signatures tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">get</span> actions<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../globals.html#dictionary" class="tsd-signature-type">Dictionary</a><span class="tsd-signature-symbol"><</span><a href="../globals.html#actioncreator" class="tsd-signature-type">ActionCreator</a><span class="tsd-signature-symbol">></span></li>
|
||||
</ul>
|
||||
<ul class="tsd-descriptions">
|
||||
<li class="tsd-description">
|
||||
<aside class="tsd-sources">
|
||||
<ul>
|
||||
<li>Defined in updux.ts:156</li>
|
||||
</ul>
|
||||
</aside>
|
||||
<div class="tsd-comment tsd-typography">
|
||||
<div class="lead">
|
||||
<p>Action creators for all actions defined or used in the actions, mutations, effects and subduxes
|
||||
of the updux config.</p>
|
||||
</div>
|
||||
<p>Non-custom action creators defined in <code>actions</code> have the signature <code>(payload={},meta={}) => ({type,
|
||||
payload,meta})</code> (with the extra sugar that if <code>meta</code> or <code>payload</code> are not
|
||||
specified, the key is not present in the produced action).</p>
|
||||
<p>If the same action appears in multiple locations, the precedence order
|
||||
determining which one will prevail is</p>
|
||||
<pre><code>actions generated <span class="hljs-keyword">from</span> mutations/effects < non-<span class="hljs-keyword">custom</span> subduxes actions <
|
||||
<span class="hljs-keyword">custom</span> subduxes actions < <span class="hljs-keyword">custom</span> actions</code></pre>
|
||||
</div>
|
||||
<h4 class="tsd-returns-title">Returns <a href="../globals.html#dictionary" class="tsd-signature-type">Dictionary</a><span class="tsd-signature-symbol"><</span><a href="../globals.html#actioncreator" class="tsd-signature-type">ActionCreator</a><span class="tsd-signature-symbol">></span></h4>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="tsd-panel tsd-member tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<a name="asdux" class="tsd-anchor"></a>
|
||||
<h3>as<wbr>Dux</h3>
|
||||
<ul class="tsd-signatures tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">get</span> asDux<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../globals.html#dux" class="tsd-signature-type">Dux</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">></span></li>
|
||||
</ul>
|
||||
<ul class="tsd-descriptions">
|
||||
<li class="tsd-description">
|
||||
<aside class="tsd-sources">
|
||||
<ul>
|
||||
<li>Defined in updux.ts:231</li>
|
||||
</ul>
|
||||
</aside>
|
||||
<div class="tsd-comment tsd-typography">
|
||||
<div class="lead">
|
||||
<p>Returns a
|
||||
<a href="https://github.com/erikras/ducks-modular-redux">ducks</a>-like
|
||||
plain object holding the reducer from the Updux object and all
|
||||
its trimmings.</p>
|
||||
</div>
|
||||
</div>
|
||||
<h4 class="tsd-returns-title">Returns <a href="../globals.html#dux" class="tsd-signature-type">Dux</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">></span></h4>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="tsd-panel tsd-member tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<a name="createstore" class="tsd-anchor"></a>
|
||||
<h3>create<wbr>Store</h3>
|
||||
<ul class="tsd-signatures tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">get</span> createStore<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">function</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-descriptions">
|
||||
<li class="tsd-description">
|
||||
<aside class="tsd-sources">
|
||||
<ul>
|
||||
<li>Defined in updux.ts:214</li>
|
||||
</ul>
|
||||
</aside>
|
||||
<div class="tsd-comment tsd-typography">
|
||||
<div class="lead">
|
||||
<p>Same as doing</p>
|
||||
</div>
|
||||
<pre><code>import { createStore, applyMiddleware } <span class="hljs-keyword">from</span> <span class="hljs-string">'redux'</span>;
|
||||
|
||||
const { initial, reducer, middleware, actions } = updox(<span class="hljs-built_in">..</span>.);
|
||||
|
||||
const store = createStore( initial, reducer, applyMiddleware(middleware) );
|
||||
|
||||
<span class="hljs-keyword">for</span> ( let<span class="hljs-built_in"> type </span><span class="hljs-keyword">in</span> actions ) {
|
||||
store.dispatch[type] = (<span class="hljs-built_in">..</span>.args) => {
|
||||
store.dispatch(actions[type](<span class="hljs-built_in">..</span>.args))
|
||||
};
|
||||
}</code></pre><p>So that later on you can do</p>
|
||||
<pre><code>store.dispatch.addTodo<span class="hljs-comment">(...)</span>;
|
||||
|
||||
<span class="hljs-comment">// still work</span>
|
||||
store.dispatch<span class="hljs-comment">( actions.addTodo(...)</span> );</code></pre>
|
||||
</div>
|
||||
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">function</span></h4>
|
||||
<ul class="tsd-parameters">
|
||||
<li class="tsd-parameter-siganture">
|
||||
<ul class="tsd-signatures tsd-kind-type-literal">
|
||||
<li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../globals.html#storewithdispatchactions" class="tsd-signature-type">StoreWithDispatchActions</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">></span></li>
|
||||
</ul>
|
||||
<ul class="tsd-descriptions">
|
||||
<li class="tsd-description">
|
||||
<h4 class="tsd-returns-title">Returns <a href="../globals.html#storewithdispatchactions" class="tsd-signature-type">StoreWithDispatchActions</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">></span></h4>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="tsd-panel tsd-member tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<a name="middleware" class="tsd-anchor"></a>
|
||||
<h3>middleware</h3>
|
||||
<ul class="tsd-signatures tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">get</span> middleware<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Middleware</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">__type</span><span class="tsd-signature-symbol">, </span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">, </span><a href="../globals.html#upduxdispatch" class="tsd-signature-type">UpduxDispatch</a><span class="tsd-signature-symbol">></span></li>
|
||||
</ul>
|
||||
<ul class="tsd-descriptions">
|
||||
<li class="tsd-description">
|
||||
<aside class="tsd-sources">
|
||||
<ul>
|
||||
<li>Defined in updux.ts:134</li>
|
||||
</ul>
|
||||
</aside>
|
||||
<div class="tsd-comment tsd-typography">
|
||||
<div class="lead">
|
||||
<p>A middleware aggregating all the effects defined in the
|
||||
updux and its subduxes. Effects of the updux itself are
|
||||
done before the subduxes effects.</p>
|
||||
</div>
|
||||
</div>
|
||||
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Middleware</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">__type</span><span class="tsd-signature-symbol">, </span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">, </span><a href="../globals.html#upduxdispatch" class="tsd-signature-type">UpduxDispatch</a><span class="tsd-signature-symbol">></span></h4>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="tsd-panel tsd-member tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<a name="mutations" class="tsd-anchor"></a>
|
||||
<h3>mutations</h3>
|
||||
<ul class="tsd-signatures tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">get</span> mutations<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../globals.html#dictionary" class="tsd-signature-type">Dictionary</a><span class="tsd-signature-symbol"><</span><a href="../globals.html#mutation" class="tsd-signature-type">Mutation</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">></span></li>
|
||||
</ul>
|
||||
<ul class="tsd-descriptions">
|
||||
<li class="tsd-description">
|
||||
<aside class="tsd-sources">
|
||||
<ul>
|
||||
<li>Defined in updux.ts:185</li>
|
||||
</ul>
|
||||
</aside>
|
||||
<div class="tsd-comment tsd-typography">
|
||||
<div class="lead">
|
||||
<p>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.</p>
|
||||
</div>
|
||||
</div>
|
||||
<h4 class="tsd-returns-title">Returns <a href="../globals.html#dictionary" class="tsd-signature-type">Dictionary</a><span class="tsd-signature-symbol"><</span><a href="../globals.html#mutation" class="tsd-signature-type">Mutation</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">></span></h4>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="tsd-panel tsd-member tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<a name="reducer" class="tsd-anchor"></a>
|
||||
<h3>reducer</h3>
|
||||
<ul class="tsd-signatures tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">get</span> reducer<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">function</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-descriptions">
|
||||
<li class="tsd-description">
|
||||
<aside class="tsd-sources">
|
||||
<ul>
|
||||
<li>Defined in updux.ts:176</li>
|
||||
</ul>
|
||||
</aside>
|
||||
<div class="tsd-comment tsd-typography">
|
||||
<div class="lead">
|
||||
<p>A Redux reducer generated using the computed initial state and
|
||||
mutations.</p>
|
||||
</div>
|
||||
</div>
|
||||
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">function</span></h4>
|
||||
<ul class="tsd-parameters">
|
||||
<li class="tsd-parameter-siganture">
|
||||
<ul class="tsd-signatures tsd-kind-type-literal">
|
||||
<li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">(</span>state<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">undefined</span>, action<span class="tsd-signature-symbol">: </span><a href="../globals.html#action" class="tsd-signature-type">Action</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">S</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-descriptions">
|
||||
<li class="tsd-description">
|
||||
<h4 class="tsd-parameters-title">Parameters</h4>
|
||||
<ul class="tsd-parameters">
|
||||
<li>
|
||||
<h5>state: <span class="tsd-signature-type">S</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">undefined</span></h5>
|
||||
</li>
|
||||
<li>
|
||||
<h5>action: <a href="../globals.html#action" class="tsd-signature-type">Action</a></h5>
|
||||
</li>
|
||||
</ul>
|
||||
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">S</span></h4>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="tsd-panel tsd-member tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<a name="upreducer" class="tsd-anchor"></a>
|
||||
<h3>upreducer</h3>
|
||||
<ul class="tsd-signatures tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">get</span> upreducer<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../globals.html#upreducer" class="tsd-signature-type">Upreducer</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">></span></li>
|
||||
</ul>
|
||||
<ul class="tsd-descriptions">
|
||||
<li class="tsd-description">
|
||||
<aside class="tsd-sources">
|
||||
<ul>
|
||||
<li>Defined in updux.ts:168</li>
|
||||
</ul>
|
||||
</aside>
|
||||
<h4 class="tsd-returns-title">Returns <a href="../globals.html#upreducer" class="tsd-signature-type">Upreducer</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">></span></h4>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
</section>
|
||||
<section class="tsd-panel-group tsd-member-group ">
|
||||
<h2>Methods</h2>
|
||||
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter">
|
||||
<a name="addmutation" class="tsd-anchor"></a>
|
||||
<h3>add<wbr>Mutation</h3>
|
||||
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter">
|
||||
<li class="tsd-signature tsd-kind-icon">add<wbr>Mutation<A><span class="tsd-signature-symbol">(</span>creator<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">A</span>, mutation<span class="tsd-signature-symbol">: </span><a href="../globals.html#mutation" class="tsd-signature-type">Mutation</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">, </span><span class="tsd-signature-type">A extends (...args: any[]) => infer R ? R : never</span><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-descriptions">
|
||||
<li class="tsd-description">
|
||||
<aside class="tsd-sources">
|
||||
<ul>
|
||||
<li>Defined in updux.ts:253</li>
|
||||
</ul>
|
||||
</aside>
|
||||
<div class="tsd-comment tsd-typography">
|
||||
<div class="lead">
|
||||
<p>Adds a mutation and its associated action to the updux.
|
||||
If a local mutation was already associated to the action,
|
||||
it will be replaced by the new one.</p>
|
||||
</div>
|
||||
<dl class="tsd-comment-tags">
|
||||
<dt>example</dt>
|
||||
<dd><pre><code>updux.addMutation( add, inc => <span class="hljs-keyword">state</span> => <span class="hljs-keyword">state</span> + inc );</code></pre></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<h4 class="tsd-type-parameters-title">Type parameters</h4>
|
||||
<ul class="tsd-type-parameters">
|
||||
<li>
|
||||
<h4>A<span class="tsd-signature-symbol">: </span><a href="../globals.html#actioncreator" class="tsd-signature-type">ActionCreator</a></h4>
|
||||
</li>
|
||||
</ul>
|
||||
<h4 class="tsd-parameters-title">Parameters</h4>
|
||||
<ul class="tsd-parameters">
|
||||
<li>
|
||||
<h5>creator: <span class="tsd-signature-type">A</span></h5>
|
||||
</li>
|
||||
<li>
|
||||
<h5>mutation: <a href="../globals.html#mutation" class="tsd-signature-type">Mutation</a><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">S</span><span class="tsd-signature-symbol">, </span><span class="tsd-signature-type">A extends (...args: any[]) => infer R ? R : never</span><span class="tsd-signature-symbol">></span></h5>
|
||||
</li>
|
||||
</ul>
|
||||
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
</section>
|
||||
</div>
|
||||
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
|
||||
<nav class="tsd-navigation primary">
|
||||
<ul>
|
||||
<li class="globals ">
|
||||
<a href="../globals.html"><em>Globals</em></a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<nav class="tsd-navigation secondary menu-sticky">
|
||||
<ul class="before-current">
|
||||
</ul>
|
||||
<ul class="current">
|
||||
<li class="current tsd-kind-class tsd-has-type-parameter">
|
||||
<a href="updux.html" class="tsd-kind-icon">Updux</a>
|
||||
<ul>
|
||||
<li class=" tsd-kind-constructor tsd-parent-kind-class">
|
||||
<a href="updux.html#constructor" class="tsd-kind-icon">constructor</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-property tsd-parent-kind-class">
|
||||
<a href="updux.html#groommutations" class="tsd-kind-icon">groom<wbr>Mutations</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-property tsd-parent-kind-class">
|
||||
<a href="updux.html#initial" class="tsd-kind-icon">initial</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-property tsd-parent-kind-class">
|
||||
<a href="updux.html#subduxes" class="tsd-kind-icon">subduxes</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<a href="updux.html#actions" class="tsd-kind-icon">actions</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<a href="updux.html#asdux" class="tsd-kind-icon">as<wbr>Dux</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<a href="updux.html#createstore" class="tsd-kind-icon">create<wbr>Store</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<a href="updux.html#middleware" class="tsd-kind-icon">middleware</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<a href="updux.html#mutations" class="tsd-kind-icon">mutations</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<a href="updux.html#reducer" class="tsd-kind-icon">reducer</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-get-signature tsd-parent-kind-class">
|
||||
<a href="updux.html#upreducer" class="tsd-kind-icon">upreducer</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-method tsd-parent-kind-class tsd-has-type-parameter">
|
||||
<a href="updux.html#addmutation" class="tsd-kind-icon">add<wbr>Mutation</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="after-current">
|
||||
<li class=" tsd-kind-type-alias tsd-has-type-parameter">
|
||||
<a href="../globals.html#action" class="tsd-kind-icon">Action</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-has-type-parameter">
|
||||
<a href="../globals.html#actioncreator" class="tsd-kind-icon">Action<wbr>Creator</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-is-not-exported">
|
||||
<a href="../globals.html#actionpair" class="tsd-kind-icon">Action<wbr>Pair</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias">
|
||||
<a href="../globals.html#actionpayloadgenerator" class="tsd-kind-icon">Action<wbr>Payload<wbr>Generator</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-has-type-parameter">
|
||||
<a href="../globals.html#dictionary" class="tsd-kind-icon">Dictionary</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-has-type-parameter">
|
||||
<a href="../globals.html#dux" class="tsd-kind-icon">Dux</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-has-type-parameter tsd-is-not-exported">
|
||||
<a href="../globals.html#maybepayload" class="tsd-kind-icon">Maybe<wbr>Payload</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-has-type-parameter">
|
||||
<a href="../globals.html#mutation" class="tsd-kind-icon">Mutation</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-is-not-exported">
|
||||
<a href="../globals.html#mystate" class="tsd-kind-icon">My<wbr>State</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-is-not-exported">
|
||||
<a href="../globals.html#next" class="tsd-kind-icon">Next</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-has-type-parameter tsd-is-not-exported">
|
||||
<a href="../globals.html#storewithdispatchactions" class="tsd-kind-icon">Store<wbr>With<wbr>Dispatch<wbr>Actions</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-is-not-exported">
|
||||
<a href="../globals.html#submutations" class="tsd-kind-icon">Sub<wbr>Mutations</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-has-type-parameter">
|
||||
<a href="../globals.html#upduxconfig" class="tsd-kind-icon">Updux<wbr>Config</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias">
|
||||
<a href="../globals.html#upduxdispatch" class="tsd-kind-icon">Updux<wbr>Dispatch</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-has-type-parameter">
|
||||
<a href="../globals.html#upreducer" class="tsd-kind-icon">Upreducer</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-is-not-exported">
|
||||
<a href="../globals.html#middlewarefor" class="tsd-kind-icon">Middleware<wbr>For</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-has-type-parameter">
|
||||
<a href="../globals.html#actioncreator" class="tsd-kind-icon">action<wbr>Creator</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-is-not-exported">
|
||||
<a href="../globals.html#actionfor" class="tsd-kind-icon">action<wbr>For</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function">
|
||||
<a href="../globals.html#buildactions" class="tsd-kind-icon">build<wbr>Actions</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-has-type-parameter">
|
||||
<a href="../globals.html#buildcreatestore" class="tsd-kind-icon">build<wbr>Create<wbr>Store</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-has-type-parameter">
|
||||
<a href="../globals.html#buildinitial" class="tsd-kind-icon">build<wbr>Initial</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-has-type-parameter">
|
||||
<a href="../globals.html#buildmiddleware" class="tsd-kind-icon">build<wbr>Middleware</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function">
|
||||
<a href="../globals.html#buildmutations" class="tsd-kind-icon">build<wbr>Mutations</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-has-type-parameter">
|
||||
<a href="../globals.html#buildupreducer" class="tsd-kind-icon">build<wbr>Upreducer</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-is-not-exported">
|
||||
<a href="../globals.html#composemutations" class="tsd-kind-icon">compose<wbr>Mutations</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-is-not-exported">
|
||||
<a href="../globals.html#noopeffect" class="tsd-kind-icon">noop<wbr>Effect</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-is-not-exported">
|
||||
<a href="../globals.html#timeout" class="tsd-kind-icon">timeout</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-is-not-exported">
|
||||
<a href="../globals.html#tracer" class="tsd-kind-icon">tracer</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<footer class="with-border-bottom">
|
||||
<div class="container">
|
||||
<h2>Legend</h2>
|
||||
<div class="tsd-legend-group">
|
||||
<ul class="tsd-legend">
|
||||
<li class="tsd-kind-module"><span class="tsd-kind-icon">Module</span></li>
|
||||
<li class="tsd-kind-object-literal"><span class="tsd-kind-icon">Object literal</span></li>
|
||||
<li class="tsd-kind-variable"><span class="tsd-kind-icon">Variable</span></li>
|
||||
<li class="tsd-kind-function"><span class="tsd-kind-icon">Function</span></li>
|
||||
<li class="tsd-kind-function tsd-has-type-parameter"><span class="tsd-kind-icon">Function with type parameter</span></li>
|
||||
<li class="tsd-kind-index-signature"><span class="tsd-kind-icon">Index signature</span></li>
|
||||
<li class="tsd-kind-type-alias"><span class="tsd-kind-icon">Type alias</span></li>
|
||||
<li class="tsd-kind-type-alias tsd-has-type-parameter"><span class="tsd-kind-icon">Type alias with type parameter</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-legend">
|
||||
<li class="tsd-kind-enum"><span class="tsd-kind-icon">Enumeration</span></li>
|
||||
<li class="tsd-kind-enum-member"><span class="tsd-kind-icon">Enumeration member</span></li>
|
||||
<li class="tsd-kind-property tsd-parent-kind-enum"><span class="tsd-kind-icon">Property</span></li>
|
||||
<li class="tsd-kind-method tsd-parent-kind-enum"><span class="tsd-kind-icon">Method</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-legend">
|
||||
<li class="tsd-kind-interface"><span class="tsd-kind-icon">Interface</span></li>
|
||||
<li class="tsd-kind-interface tsd-has-type-parameter"><span class="tsd-kind-icon">Interface with type parameter</span></li>
|
||||
<li class="tsd-kind-constructor tsd-parent-kind-interface"><span class="tsd-kind-icon">Constructor</span></li>
|
||||
<li class="tsd-kind-property tsd-parent-kind-interface"><span class="tsd-kind-icon">Property</span></li>
|
||||
<li class="tsd-kind-method tsd-parent-kind-interface"><span class="tsd-kind-icon">Method</span></li>
|
||||
<li class="tsd-kind-index-signature tsd-parent-kind-interface"><span class="tsd-kind-icon">Index signature</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-legend">
|
||||
<li class="tsd-kind-class"><span class="tsd-kind-icon">Class</span></li>
|
||||
<li class="tsd-kind-class tsd-has-type-parameter"><span class="tsd-kind-icon">Class with type parameter</span></li>
|
||||
<li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li>
|
||||
<li class="tsd-kind-property tsd-parent-kind-class"><span class="tsd-kind-icon">Property</span></li>
|
||||
<li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li>
|
||||
<li class="tsd-kind-accessor tsd-parent-kind-class"><span class="tsd-kind-icon">Accessor</span></li>
|
||||
<li class="tsd-kind-index-signature tsd-parent-kind-class"><span class="tsd-kind-icon">Index signature</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-legend">
|
||||
<li class="tsd-kind-constructor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited constructor</span></li>
|
||||
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited property</span></li>
|
||||
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited method</span></li>
|
||||
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited accessor</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-legend">
|
||||
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected property</span></li>
|
||||
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected method</span></li>
|
||||
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected accessor</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-legend">
|
||||
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private property</span></li>
|
||||
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private method</span></li>
|
||||
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private accessor</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-legend">
|
||||
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static property</span></li>
|
||||
<li class="tsd-kind-call-signature tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static method</span></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
<div class="container tsd-generator">
|
||||
<p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p>
|
||||
</div>
|
||||
<div class="overlay"></div>
|
||||
<script src="../assets/js/main.js"></script>
|
||||
<script>if (location.protocol == 'file:') document.write('<script src="../assets/js/search.js"><' + '/script>');</script>
|
||||
</body>
|
||||
</html>
|
File diff suppressed because one or more lines are too long
1287
docs/globals.html
1287
docs/globals.html
File diff suppressed because it is too large
Load Diff
393
docs/index.html
393
docs/index.html
|
@ -1,379 +1,24 @@
|
|||
<!doctype html>
|
||||
<html class="default no-js">
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>updux</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="assets/css/main.css">
|
||||
<meta charset="UTF-8">
|
||||
<title>Document</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<meta name="description" content="Description">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
|
||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<div class="tsd-page-toolbar">
|
||||
<div class="container">
|
||||
<div class="table-wrap">
|
||||
<div class="table-cell" id="tsd-search" data-index="assets/js/search.js" data-base=".">
|
||||
<div class="field">
|
||||
<label for="tsd-search-field" class="tsd-widget search no-caption">Search</label>
|
||||
<input id="tsd-search-field" type="text" />
|
||||
</div>
|
||||
<ul class="results">
|
||||
<li class="state loading">Preparing search index...</li>
|
||||
<li class="state failure">The search index is not available</li>
|
||||
</ul>
|
||||
<a href="index.html" class="title">updux</a>
|
||||
</div>
|
||||
<div class="table-cell" id="tsd-widgets">
|
||||
<div id="tsd-filter">
|
||||
<a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a>
|
||||
<div class="tsd-filter-group">
|
||||
<div class="tsd-select" id="tsd-filter-visibility">
|
||||
<span class="tsd-select-label">All</span>
|
||||
<ul class="tsd-select-list">
|
||||
<li data-value="public">Public</li>
|
||||
<li data-value="protected">Public/Protected</li>
|
||||
<li data-value="private" class="selected">All</li>
|
||||
</ul>
|
||||
</div>
|
||||
<input type="checkbox" id="tsd-filter-inherited" checked />
|
||||
<label class="tsd-widget" for="tsd-filter-inherited">Inherited</label>
|
||||
<input type="checkbox" id="tsd-filter-externals" checked />
|
||||
<label class="tsd-widget" for="tsd-filter-externals">Externals</label>
|
||||
<input type="checkbox" id="tsd-filter-only-exported" />
|
||||
<label class="tsd-widget" for="tsd-filter-only-exported">Only exported</label>
|
||||
</div>
|
||||
</div>
|
||||
<a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tsd-page-title">
|
||||
<div class="container">
|
||||
<ul class="tsd-breadcrumb">
|
||||
<li>
|
||||
<a href="globals.html">Globals</a>
|
||||
</li>
|
||||
</ul>
|
||||
<h1> updux</h1>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div class="container container-main">
|
||||
<div class="row">
|
||||
<div class="col-8 col-content">
|
||||
<div class="tsd-panel tsd-typography">
|
||||
<a href="#what39s-updux" id="what39s-updux" style="color: inherit; text-decoration: none;">
|
||||
<h1>What's Updux?</h1>
|
||||
</a>
|
||||
<p>So, I'm a fan of <a href="https://redux.js.org">Redux</a>. Two days ago I discovered
|
||||
<a href="https://rematch.github.io/rematch">rematch</a> alonside a few other frameworks built atop Redux. </p>
|
||||
<p>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!</p>
|
||||
<p>But it also enforces a flat hierarchy of reducers -- where
|
||||
is the fun in that? And I'm also having a strong love for
|
||||
<a href="https://github.com/substantial/updeep">Updeep</a>, so I want reducer state updates to leverage the heck out of it.</p>
|
||||
<p>All that to say, say hello to <code>Updux</code>. Heavily inspired by <code>rematch</code>, but twisted
|
||||
to work with <code>updeep</code> and to fit my peculiar needs. It offers features such as</p>
|
||||
<ul>
|
||||
<li>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.</li>
|
||||
<li>Automatically gather all actions used by the updux's effects and mutations,
|
||||
and makes then accessible as attributes to the <code>dispatch</code> object of the
|
||||
store.</li>
|
||||
<li>Mutations have a signature that is friendly to Updux and Immer.</li>
|
||||
<li>Also, the mutation signature auto-unwrap the payload of the actions for you.</li>
|
||||
<li>TypeScript types.</li>
|
||||
</ul>
|
||||
<p>Fair warning: this package is still very new, probably very buggy,
|
||||
definitively very badly documented, and very subject to changes. Caveat
|
||||
Maxima Emptor.</p>
|
||||
<a href="#synopsis" id="synopsis" style="color: inherit; text-decoration: none;">
|
||||
<h1>Synopsis</h1>
|
||||
</a>
|
||||
<pre><code><span class="hljs-keyword">import</span> updux <span class="hljs-keyword">from</span> <span class="hljs-string">'updux'</span>;
|
||||
|
||||
<span class="hljs-keyword">import</span> otherUpdux <span class="hljs-keyword">from</span> <span class="hljs-string">'./otherUpdux'</span>;
|
||||
|
||||
<span class="hljs-keyword">const</span> {
|
||||
initial,
|
||||
reducer,
|
||||
actions,
|
||||
middleware,
|
||||
createStore,
|
||||
} = <span class="hljs-keyword">new</span> Updux({
|
||||
<span class="hljs-attr">initial</span>: {
|
||||
<span class="hljs-attr">counter</span>: <span class="hljs-number">0</span>,
|
||||
},
|
||||
<span class="hljs-attr">subduxes</span>: {
|
||||
otherUpdux,
|
||||
},
|
||||
<span class="hljs-attr">mutations</span>: {
|
||||
<span class="hljs-attr">inc</span>: <span class="hljs-function">(<span class="hljs-params"> increment = <span class="hljs-number">1</span> </span>) =></span> u({<span class="hljs-attr">counter</span>: <span class="hljs-function"><span class="hljs-params">s</span> =></span> s + increment })
|
||||
},
|
||||
<span class="hljs-attr">effects</span>: {
|
||||
<span class="hljs-string">'*'</span> => <span class="hljs-function"><span class="hljs-params">api</span> =></span> <span class="hljs-function"><span class="hljs-params">next</span> =></span> <span class="hljs-function"><span class="hljs-params">action</span> =></span> {
|
||||
<span class="hljs-built_in">console</span>.log( <span class="hljs-string">"hey, look, an action zoomed by!"</span>, action );
|
||||
next(action);
|
||||
};
|
||||
},
|
||||
<span class="hljs-attr">actions</span>: {
|
||||
<span class="hljs-attr">customAction</span>: <span class="hljs-function">(<span class="hljs-params"> someArg </span>) =></span> ({
|
||||
<span class="hljs-attr">type</span>: <span class="hljs-string">"custom"</span>,
|
||||
<span class="hljs-attr">payload</span>: { <span class="hljs-attr">someProp</span>: someArg }
|
||||
}),
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
<span class="hljs-keyword">const</span> store = createStore();
|
||||
|
||||
store.dispatch.inc(<span class="hljs-number">3</span>);</code></pre>
|
||||
<a href="#description" id="description" style="color: inherit; text-decoration: none;">
|
||||
<h1>Description</h1>
|
||||
</a>
|
||||
<p>The formal documentation of the class Updux and its associated functions and
|
||||
types can be found over <a href="./docs/classes/updux.html">here</a>.</p>
|
||||
<a href="#exporting-upduxes" id="exporting-upduxes" style="color: inherit; text-decoration: none;">
|
||||
<h2>Exporting upduxes</h2>
|
||||
</a>
|
||||
<p>If you are creating upduxes that will be used as subduxes
|
||||
by other upduxes, or as
|
||||
<a href="https://github.com/erikras/ducks-modular-redux">ducks</a>-like containers, I
|
||||
recommend that you export the Updux instance as the default export:</p>
|
||||
<pre><code>import Updux <span class="hljs-keyword">from</span> <span class="hljs-string">'updux'</span>;
|
||||
|
||||
const updux = new Updux({ <span class="hljs-built_in">..</span>. });
|
||||
|
||||
<span class="hljs-builtin-name">export</span><span class="hljs-built_in"> default </span>updux;</code></pre><p>Then you can use them as subduxes like this:</p>
|
||||
<pre><code><span class="hljs-keyword">import</span> Updux <span class="hljs-keyword">from</span> <span class="hljs-string">'updux'</span>;
|
||||
<span class="hljs-keyword">import</span> foo <span class="hljs-keyword">from</span> <span class="hljs-string">'./foo'</span>; <span class="hljs-comment">// foo is an Updux</span>
|
||||
<span class="hljs-keyword">import</span> bar <span class="hljs-keyword">from</span> <span class="hljs-string">'./bar'</span>; <span class="hljs-comment">// bar is an Updux as well</span>
|
||||
|
||||
<span class="hljs-keyword">const</span> updux = <span class="hljs-keyword">new</span> Updux({
|
||||
<span class="hljs-attr">subduxes</span>: {
|
||||
foo, bar
|
||||
<div id="app"></div>
|
||||
<script>
|
||||
window.$docsify = {
|
||||
loadSidebar: true,
|
||||
name: 'updux',
|
||||
repo: '',
|
||||
subMaxLevel: 3,
|
||||
}
|
||||
});</code></pre><p>Or if you want to use it:</p>
|
||||
<pre><code><span class="hljs-keyword">import</span> updux <span class="hljs-keyword">from</span> <span class="hljs-string">'./myUpdux'</span>;
|
||||
|
||||
<span class="hljs-keyword">const</span> {
|
||||
reducer,
|
||||
<span class="hljs-attr">actions</span>: { doTheThing },
|
||||
createStore,
|
||||
middleware,
|
||||
} = updux;</code></pre>
|
||||
<a href="#usage-with-immer" id="usage-with-immer" style="color: inherit; text-decoration: none;">
|
||||
<h2>Usage with Immer</h2>
|
||||
</a>
|
||||
<p>While Updux was created with Updeep in mind, it also plays very
|
||||
well with <a href="https://immerjs.github.io/immer/docs/introduction">Immer</a>.</p>
|
||||
<p>For example, taking this basic updux:</p>
|
||||
<pre><code><span class="hljs-keyword">import</span> Updux <span class="hljs-keyword">from</span> <span class="hljs-string">'updux'</span>;
|
||||
|
||||
<span class="hljs-keyword">const</span> updux = <span class="hljs-keyword">new</span> Updux({
|
||||
<span class="hljs-attr">initial</span>: { <span class="hljs-attr">counter</span>: <span class="hljs-number">0</span> },
|
||||
<span class="hljs-attr">mutations</span>: {
|
||||
<span class="hljs-attr">add</span>: <span class="hljs-function">(<span class="hljs-params">inc=<span class="hljs-number">1</span></span>) =></span> <span class="hljs-function"><span class="hljs-params">state</span> =></span> { <span class="hljs-attr">counter</span>: counter + inc }
|
||||
}
|
||||
});
|
||||
</code></pre><p>Converting it to Immer would look like:</p>
|
||||
<pre><code><span class="hljs-keyword">import</span> Updux <span class="hljs-keyword">from</span> <span class="hljs-string">'updux'</span>;
|
||||
<span class="hljs-keyword">import</span> { produce } <span class="hljs-keyword">from</span> <span class="hljs-string">'Immer'</span>;
|
||||
|
||||
<span class="hljs-keyword">const</span> updux = <span class="hljs-keyword">new</span> Updux({
|
||||
<span class="hljs-attr">initial</span>: { <span class="hljs-attr">counter</span>: <span class="hljs-number">0</span> },
|
||||
<span class="hljs-attr">mutations</span>: {
|
||||
<span class="hljs-attr">add</span>: <span class="hljs-function">(<span class="hljs-params">inc=<span class="hljs-number">1</span></span>) =></span> produce( <span class="hljs-function"><span class="hljs-params">draft</span> =></span> draft.counter += inc ) }
|
||||
}
|
||||
});
|
||||
</code></pre><p>But since typing <code>produce</code> over and over is no fun, <code>groomMutations</code>
|
||||
can be used to wrap all mutations with it:</p>
|
||||
<pre><code><span class="hljs-keyword">import</span> Updux <span class="hljs-keyword">from</span> <span class="hljs-string">'updux'</span>;
|
||||
<span class="hljs-keyword">import</span> { produce } <span class="hljs-keyword">from</span> <span class="hljs-string">'Immer'</span>;
|
||||
|
||||
<span class="hljs-keyword">const</span> updux = <span class="hljs-keyword">new</span> Updux({
|
||||
<span class="hljs-attr">initial</span>: { <span class="hljs-attr">counter</span>: <span class="hljs-number">0</span> },
|
||||
<span class="hljs-attr">groomMutations</span>: <span class="hljs-function"><span class="hljs-params">mutation</span> =></span> <span class="hljs-function">(<span class="hljs-params">...args</span>) =></span> produce( mutation(...args) ),
|
||||
<span class="hljs-attr">mutations</span>: {
|
||||
<span class="hljs-attr">add</span>: <span class="hljs-function">(<span class="hljs-params">inc=<span class="hljs-number">1</span></span>) =></span> <span class="hljs-function"><span class="hljs-params">draft</span> =></span> draft.counter += inc
|
||||
}
|
||||
});
|
||||
</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
|
||||
<nav class="tsd-navigation primary">
|
||||
<ul>
|
||||
<li class="globals ">
|
||||
<a href="globals.html"><em>Globals</em></a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<nav class="tsd-navigation secondary menu-sticky">
|
||||
<ul class="before-current">
|
||||
<li class=" tsd-kind-class tsd-has-type-parameter">
|
||||
<a href="classes/updux.html" class="tsd-kind-icon">Updux</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-has-type-parameter">
|
||||
<a href="globals.html#action" class="tsd-kind-icon">Action</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-has-type-parameter">
|
||||
<a href="globals.html#actioncreator" class="tsd-kind-icon">Action<wbr>Creator</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-is-not-exported">
|
||||
<a href="globals.html#actionpair" class="tsd-kind-icon">Action<wbr>Pair</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias">
|
||||
<a href="globals.html#actionpayloadgenerator" class="tsd-kind-icon">Action<wbr>Payload<wbr>Generator</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-has-type-parameter">
|
||||
<a href="globals.html#dictionary" class="tsd-kind-icon">Dictionary</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-has-type-parameter">
|
||||
<a href="globals.html#dux" class="tsd-kind-icon">Dux</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-has-type-parameter tsd-is-not-exported">
|
||||
<a href="globals.html#maybepayload" class="tsd-kind-icon">Maybe<wbr>Payload</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-has-type-parameter">
|
||||
<a href="globals.html#mutation" class="tsd-kind-icon">Mutation</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-is-not-exported">
|
||||
<a href="globals.html#mystate" class="tsd-kind-icon">My<wbr>State</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-is-not-exported">
|
||||
<a href="globals.html#next" class="tsd-kind-icon">Next</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-has-type-parameter tsd-is-not-exported">
|
||||
<a href="globals.html#storewithdispatchactions" class="tsd-kind-icon">Store<wbr>With<wbr>Dispatch<wbr>Actions</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-is-not-exported">
|
||||
<a href="globals.html#submutations" class="tsd-kind-icon">Sub<wbr>Mutations</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-has-type-parameter">
|
||||
<a href="globals.html#upduxconfig" class="tsd-kind-icon">Updux<wbr>Config</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias">
|
||||
<a href="globals.html#upduxdispatch" class="tsd-kind-icon">Updux<wbr>Dispatch</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-type-alias tsd-has-type-parameter">
|
||||
<a href="globals.html#upreducer" class="tsd-kind-icon">Upreducer</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-is-not-exported">
|
||||
<a href="globals.html#middlewarefor" class="tsd-kind-icon">Middleware<wbr>For</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-has-type-parameter">
|
||||
<a href="globals.html#actioncreator" class="tsd-kind-icon">action<wbr>Creator</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-is-not-exported">
|
||||
<a href="globals.html#actionfor" class="tsd-kind-icon">action<wbr>For</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function">
|
||||
<a href="globals.html#buildactions" class="tsd-kind-icon">build<wbr>Actions</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-has-type-parameter">
|
||||
<a href="globals.html#buildcreatestore" class="tsd-kind-icon">build<wbr>Create<wbr>Store</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-has-type-parameter">
|
||||
<a href="globals.html#buildinitial" class="tsd-kind-icon">build<wbr>Initial</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-has-type-parameter">
|
||||
<a href="globals.html#buildmiddleware" class="tsd-kind-icon">build<wbr>Middleware</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function">
|
||||
<a href="globals.html#buildmutations" class="tsd-kind-icon">build<wbr>Mutations</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-has-type-parameter">
|
||||
<a href="globals.html#buildupreducer" class="tsd-kind-icon">build<wbr>Upreducer</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-is-not-exported">
|
||||
<a href="globals.html#composemutations" class="tsd-kind-icon">compose<wbr>Mutations</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-is-not-exported">
|
||||
<a href="globals.html#noopeffect" class="tsd-kind-icon">noop<wbr>Effect</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-is-not-exported">
|
||||
<a href="globals.html#timeout" class="tsd-kind-icon">timeout</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-function tsd-is-not-exported">
|
||||
<a href="globals.html#tracer" class="tsd-kind-icon">tracer</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<footer class="with-border-bottom">
|
||||
<div class="container">
|
||||
<h2>Legend</h2>
|
||||
<div class="tsd-legend-group">
|
||||
<ul class="tsd-legend">
|
||||
<li class="tsd-kind-module"><span class="tsd-kind-icon">Module</span></li>
|
||||
<li class="tsd-kind-object-literal"><span class="tsd-kind-icon">Object literal</span></li>
|
||||
<li class="tsd-kind-variable"><span class="tsd-kind-icon">Variable</span></li>
|
||||
<li class="tsd-kind-function"><span class="tsd-kind-icon">Function</span></li>
|
||||
<li class="tsd-kind-function tsd-has-type-parameter"><span class="tsd-kind-icon">Function with type parameter</span></li>
|
||||
<li class="tsd-kind-index-signature"><span class="tsd-kind-icon">Index signature</span></li>
|
||||
<li class="tsd-kind-type-alias"><span class="tsd-kind-icon">Type alias</span></li>
|
||||
<li class="tsd-kind-type-alias tsd-has-type-parameter"><span class="tsd-kind-icon">Type alias with type parameter</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-legend">
|
||||
<li class="tsd-kind-enum"><span class="tsd-kind-icon">Enumeration</span></li>
|
||||
<li class="tsd-kind-enum-member"><span class="tsd-kind-icon">Enumeration member</span></li>
|
||||
<li class="tsd-kind-property tsd-parent-kind-enum"><span class="tsd-kind-icon">Property</span></li>
|
||||
<li class="tsd-kind-method tsd-parent-kind-enum"><span class="tsd-kind-icon">Method</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-legend">
|
||||
<li class="tsd-kind-interface"><span class="tsd-kind-icon">Interface</span></li>
|
||||
<li class="tsd-kind-interface tsd-has-type-parameter"><span class="tsd-kind-icon">Interface with type parameter</span></li>
|
||||
<li class="tsd-kind-constructor tsd-parent-kind-interface"><span class="tsd-kind-icon">Constructor</span></li>
|
||||
<li class="tsd-kind-property tsd-parent-kind-interface"><span class="tsd-kind-icon">Property</span></li>
|
||||
<li class="tsd-kind-method tsd-parent-kind-interface"><span class="tsd-kind-icon">Method</span></li>
|
||||
<li class="tsd-kind-index-signature tsd-parent-kind-interface"><span class="tsd-kind-icon">Index signature</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-legend">
|
||||
<li class="tsd-kind-class"><span class="tsd-kind-icon">Class</span></li>
|
||||
<li class="tsd-kind-class tsd-has-type-parameter"><span class="tsd-kind-icon">Class with type parameter</span></li>
|
||||
<li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li>
|
||||
<li class="tsd-kind-property tsd-parent-kind-class"><span class="tsd-kind-icon">Property</span></li>
|
||||
<li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li>
|
||||
<li class="tsd-kind-accessor tsd-parent-kind-class"><span class="tsd-kind-icon">Accessor</span></li>
|
||||
<li class="tsd-kind-index-signature tsd-parent-kind-class"><span class="tsd-kind-icon">Index signature</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-legend">
|
||||
<li class="tsd-kind-constructor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited constructor</span></li>
|
||||
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited property</span></li>
|
||||
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited method</span></li>
|
||||
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited accessor</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-legend">
|
||||
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected property</span></li>
|
||||
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected method</span></li>
|
||||
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected accessor</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-legend">
|
||||
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private property</span></li>
|
||||
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private method</span></li>
|
||||
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private accessor</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-legend">
|
||||
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static property</span></li>
|
||||
<li class="tsd-kind-call-signature tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static method</span></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
<div class="container tsd-generator">
|
||||
<p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p>
|
||||
</div>
|
||||
<div class="overlay"></div>
|
||||
<script src="assets/js/main.js"></script>
|
||||
<script>if (location.protocol == 'file:') document.write('<script src="assets/js/search.js"><' + '/script>');</script>
|
||||
</script>
|
||||
<!-- Docsify v4 -->
|
||||
<script src="docsify.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
# Recipes
|
||||
|
||||
## Mapping a mutation to all values of a state
|
||||
|
||||
Say you have a `todos` state that is an array of `todo` sub-states, with some
|
||||
actions that should percolate to all todos, and some that should only
|
||||
percolate to one. One way to model this is via updux's splat subduxes
|
||||
(backed by `updeep`'s own '*'-key behavior).
|
||||
|
||||
```
|
||||
const done = () => (state) => ({...state, done: true});
|
||||
|
||||
const todo = new Updux({
|
||||
initial: { id: 0, done: false },
|
||||
actions: {
|
||||
done: null,
|
||||
doneAll: null,
|
||||
},
|
||||
mutations: {
|
||||
done,
|
||||
doneAll: done,
|
||||
},
|
||||
});
|
||||
|
||||
const todos = new Updux({
|
||||
initial: [],
|
||||
subduxes: { '*': todo },
|
||||
actions: { addTodo: null },
|
||||
mutations: {
|
||||
addTodo: text => state => [ ...state, { text } ]
|
||||
}
|
||||
});
|
||||
|
||||
todos.setMutation(
|
||||
todo.actions.done,
|
||||
(text,action) => u.map(u.if(u.is('text',text), todo.upreducer(action))),
|
||||
true // prevents the subduxes mutations to run 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: state.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
|
||||
}
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
import { test, expect } from 'vitest';
|
||||
|
||||
import u from 'updeep';
|
||||
import { Updux } from '../src/index.js';
|
||||
|
||||
const done = () => (state) => ({...state, done: true});
|
||||
|
||||
const todo = new Updux({
|
||||
initial: { id: 0, done: false },
|
||||
actions: {
|
||||
done: null,
|
||||
doneAll: null,
|
||||
},
|
||||
mutations: {
|
||||
done,
|
||||
doneAll: done,
|
||||
},
|
||||
});
|
||||
|
||||
const todos = new Updux({
|
||||
initial: [],
|
||||
subduxes: { '*': todo },
|
||||
actions: { addTodo: null },
|
||||
mutations: {
|
||||
addTodo: text => state => [ ...state, { text } ]
|
||||
}
|
||||
});
|
||||
|
||||
todos.setMutation(
|
||||
todo.actions.done,
|
||||
(text,action) => u.map(u.if(u.is('text',text), todo.upreducer(action))),
|
||||
true // prevents the subduxes mutations to run automatically
|
||||
);
|
||||
|
||||
test( "tutorial", async () => {
|
||||
const store = todos.createStore();
|
||||
|
||||
store.dispatch.addTodo('one');
|
||||
store.dispatch.addTodo('two');
|
||||
store.dispatch.addTodo('three');
|
||||
|
||||
store.dispatch.done( 'two' );
|
||||
|
||||
expect( store.getState()[1].done ).toBeTruthy();
|
||||
expect( store.getState()[2].done ).toBeFalsy();
|
||||
|
||||
store.dispatch.doneAll();
|
||||
|
||||
expect( store.getState().map( ({done}) => done ) ).toEqual([
|
||||
true, true, true
|
||||
]);
|
||||
|
||||
});
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
import { test, expect } from 'vitest';
|
||||
|
||||
import u from 'updeep';
|
||||
import { action, Updux, dux } from '../src/index.js';
|
||||
|
||||
const addTodoWithId = action('addTodoWithId');
|
||||
const incNextId = action('incNextId');
|
||||
const addTodo = action('addTodo');
|
||||
|
||||
const addTodoEffect = ({ getState, dispatch }) => next => action => {
|
||||
const id = getState.nextId();
|
||||
|
||||
dispatch.incNextId();
|
||||
|
||||
next(action);
|
||||
|
||||
dispatch.addTodoWithId({ description: action.payload, id });
|
||||
}
|
||||
|
||||
const todosDux = new Updux({
|
||||
initial: { nextId: 1, todos: [] },
|
||||
actions: { addTodo, incNextId, addTodoWithId },
|
||||
selectors: {
|
||||
nextId: ({nextId}) => nextId,
|
||||
},
|
||||
mutations: {
|
||||
addTodoWithId: (todo) => u({ todos: (todos) => [...todos, todo] }),
|
||||
incNextId: () => u({ nextId: id => id+1 }),
|
||||
},
|
||||
effects: {
|
||||
'addTodo': addTodoEffect
|
||||
}
|
||||
});
|
||||
|
||||
const store = todosDux.createStore();
|
||||
|
||||
test( "tutorial example", async () => {
|
||||
store.dispatch.addTodo('Do the thing');
|
||||
|
||||
expect( store.getState() ).toMatchObject({
|
||||
nextId:2, todos: [ { description: 'Do the thing', id: 1 } ]
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
test( "catch-all effect", () => {
|
||||
|
||||
let seen = [];
|
||||
|
||||
const foo = new Updux({
|
||||
actions: {
|
||||
one: null,
|
||||
two: null,
|
||||
},
|
||||
effects: {
|
||||
'*': (api) => next => action => {
|
||||
seen.push(action.type);
|
||||
next(action);
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
const store = foo.createStore();
|
||||
|
||||
store.dispatch.one();
|
||||
store.dispatch.two();
|
||||
|
||||
expect(seen).toEqual([ 'one', 'two' ]);
|
||||
} )
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue