Compare commits
151 Commits
v1.1.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 |
|
@ -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.
|
19
Changes
19
Changes
|
@ -1,19 +0,0 @@
|
|||
# Revision history for Updux
|
||||
|
||||
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.
|
65
README.md
65
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](https://yanick.github.io/updux/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:
|
||||
|
||||
```
|
||||
|
@ -138,12 +136,12 @@ const todo = new Updux({
|
|||
|
||||
const todos = new Updux({ initial: [] });
|
||||
|
||||
todos.addMutation(
|
||||
todo.actions.review,
|
||||
(_,action) => state => state.map( todo.upreducer(action) )
|
||||
todos.addMutation(
|
||||
todo.actions.review,
|
||||
(_,action) => state => state.map( todo.upreducer(action) )
|
||||
);
|
||||
todos.addMutation(
|
||||
todo.actions.done,
|
||||
todo.actions.done,
|
||||
(id,action) => u.map(u.if(u.is('id',id), todo.upreducer(action))),
|
||||
);
|
||||
|
||||
|
@ -166,14 +164,14 @@ const todos = new Updux({
|
|||
});
|
||||
|
||||
todos.addMutation(
|
||||
todo.actions.done,
|
||||
(id,action) => u.map(u.if(u.is('id',id), todo.upreducer(action))),
|
||||
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
|
||||
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
|
||||
|
@ -189,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';
|
||||
|
@ -205,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';
|
||||
|
@ -223,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,CA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AO,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 | ([Mutation, boolean | undefined])>, 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,GAAC,CAAC,CAAC,QAAQ,EAAC,OAAO,GAAC,SAAS,CAAC,CAAC,CAAM,EACnE,QAAQ,KAAK,mEAyDhB;AAED,eAAe,cAAc,CAAC"}
|
|
@ -1,45 +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) => {
|
||||
return updeep_1.default.updateIn(slice)(mutation(payload, action));
|
||||
};
|
||||
mergedMutations[type].push(localized);
|
||||
});
|
||||
});
|
||||
Object.entries(mutations).forEach(([type, mutation]) => {
|
||||
if (Array.isArray(mutation)) {
|
||||
if (mutation[1]) {
|
||||
mergedMutations[type] = [
|
||||
mutation[0]
|
||||
];
|
||||
}
|
||||
else
|
||||
mergedMutations[type].push(mutation[0]);
|
||||
}
|
||||
else
|
||||
mergedMutations[type].push(mutation);
|
||||
});
|
||||
return fp_1.default.mapValues(composeMutations)(mergedMutations);
|
||||
}
|
||||
exports.default = buildMutations;
|
||||
//# sourceMappingURL=index.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file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BACd,CAAA;aACJ;;gBACI,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,CAAE,QAAQ,CAAC,CAAC,CAAC,CAAE,CAAC;SAClD;;YACI,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,OAAO,YAAE,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC,eAAe,CAAC,CAAC;AACzD,CAAC;AAED,kBAAe,cAAc,CAAC"}
|
|
@ -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=mappedUpdux.test.d.ts.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"mappedUpdux.test.d.ts","sourceRoot":"","sources":["../src/mappedUpdux.test.ts"],"names":[],"mappings":""}
|
|
@ -1,28 +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"));
|
||||
const updeep_1 = __importDefault(require("updeep"));
|
||||
const todo = new updux_1.default({
|
||||
mutations: {
|
||||
review: () => updeep_1.default({ reviewed: true }),
|
||||
done: () => updeep_1.default({ done: true }),
|
||||
},
|
||||
});
|
||||
const todos = new updux_1.default({
|
||||
subduxes: { '*': todo },
|
||||
});
|
||||
todos.addMutation(todo.actions.done, (id, action) => updeep_1.default.map(updeep_1.default.if(updeep_1.default.is('id', id), todo.upreducer(action))), true);
|
||||
test('* for mapping works', () => {
|
||||
const reducer = todos.reducer;
|
||||
let state = [{ id: 0 }, { id: 1 }];
|
||||
state = reducer(state, todos.actions.review());
|
||||
state = reducer(state, todos.actions.done(1));
|
||||
expect(state).toEqual([
|
||||
{ id: 0, reviewed: true },
|
||||
{ id: 1, reviewed: true, done: true },
|
||||
]);
|
||||
});
|
||||
//# sourceMappingURL=mappedUpdux.test.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"mappedUpdux.test.js","sourceRoot":"","sources":["../src/mappedUpdux.test.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAC5B,oDAAuB;AAEvB,MAAM,IAAI,GAAG,IAAI,eAAK,CAAC;IACnB,SAAS,EAAE;QACP,MAAM,EAAE,GAAG,EAAE,CAAC,gBAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAC,CAAC;QAClC,IAAI,EAAE,GAAG,EAAE,CAAC,gBAAC,CAAC,EAAC,IAAI,EAAE,IAAI,EAAC,CAAC;KAC9B;CACJ,CAAC,CAAC;AAEH,MAAM,KAAK,GAAG,IAAI,eAAK,CAAC;IACpB,QAAQ,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE;CAC1B,CAAC,CAAC;AAEH,KAAK,CAAC,WAAW,CACb,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,EAAC,MAAM,EAAE,EAAE,CAAC,gBAAC,CAAC,GAAG,CAAC,gBAAC,CAAC,EAAE,CAAC,gBAAC,CAAC,EAAE,CAAC,IAAI,EAAC,EAAE,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAC7F,CAAC;AAEF,IAAI,CAAE,qBAAqB,EAAE,GAAG,EAAE;IAC9B,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;IAC9B,IAAI,KAAK,GAAG,CAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAC,EAAE,EAAE,CAAC,EAAE,CAAE,CAAC;IACpC,KAAK,GAAG,OAAO,CAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,CAAE,CAAC;IACjD,KAAK,GAAG,OAAO,CAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,CAAC;IAEhD,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;QAClB,EAAE,EAAE,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE;QACzB,EAAE,EAAE,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE;KACxC,CAAC,CAAC;AACP,CAAC,CAAC,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":";;;;;AAAA,yCAAsB;AAGtB,IAAI,CAAE,eAAe,EAAE,GAAG,EAAE;IAExB,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;IAEzB,MAAM,KAAK,GAAG,CAAC,IAAI,UAAK,CAAC;QACrB,OAAO,EAAE;YACL,GAAG,EAAE,CAAC,GAAO,EAAE,EAAE,CAAC,CAAC,IAAQ,EAAE,EAAE,CAAC,CAAC,MAAU,EAAE,EAAE;gBAC3C,MAAM,EAAE,CAAC;gBACT,IAAI,CAAC,MAAM,CAAC,CAAC;YACjB,CAAC;SACJ;KACJ,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IAElB,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IAEtC,KAAK,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAEhC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IAEtC,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;IAErB,MAAM,CAAC,MAAM,CAAC,CAAC,gBAAgB,EAAE,CAAC;AAEtC,CAAC,CAAC,CAAC;AAEH,IAAI,CAAE,uBAAuB,EAAE,GAAG,EAAE;IAEhC,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;IAEzB,MAAM,YAAY,GAAG,CAAE,SAAiB,EAAG,EAAE,CAAC,CAAE,GAAO,EAAG,EAAE,CAAC,CAAC,IAAQ,EAAE,EAAE,CAAC,CAAE,MAAW,EAAG,EAAE;QACzF,MAAM,C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@@
|
|||
"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"));
|
||||
const foo = new updux_1.default({
|
||||
initial: 0,
|
||||
mutations: {
|
||||
doIt: () => (state) => {
|
||||
return state + 1;
|
||||
},
|
||||
doTheThing: () => (state) => {
|
||||
return state + 3;
|
||||
},
|
||||
},
|
||||
});
|
||||
const bar = new updux_1.default({
|
||||
subduxes: { foo },
|
||||
});
|
||||
bar.addMutation(foo.actions.doTheThing, (_, action) => state => {
|
||||
return {
|
||||
...state,
|
||||
baz: bar.subduxUpreducer(action)(state),
|
||||
};
|
||||
}, true);
|
||||
bar.addMutation(foo.actions.doIt, () => (state) => ({ ...state, bar: 'yay' }), true);
|
||||
test('initial', () => {
|
||||
expect(bar.initial).toEqual({ foo: 0 });
|
||||
});
|
||||
test('foo alone', () => {
|
||||
expect(foo.reducer(undefined, foo.actions.doIt())).toEqual(1);
|
||||
});
|
||||
test('sink mutations', () => {
|
||||
expect(bar.reducer(undefined, bar.actions.doIt())).toEqual({
|
||||
foo: 0,
|
||||
bar: 'yay',
|
||||
});
|
||||
});
|
||||
test('sink mutation and subduxUpreducer', () => {
|
||||
expect(bar.reducer(undefined, bar.actions.doTheThing())).toEqual({
|
||||
foo: 0,
|
||||
baz: { foo: 3 },
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=sink.test.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"sink.test.js","sourceRoot":"","sources":["../src/sink.test.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAE5B,MAAM,GAAG,GAAG,IAAI,eAAK,CAAS;IAC5B,OAAO,EAAE,CAAC;IACV,SAAS,EAAE;QACT,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,KAAa,EAAE,EAAE;YAC5B,OAAO,KAAK,GAAG,CAAC,C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,CAAC,OAAO,CAAC;QACzD,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,KAAK;KACX,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,mCAAmC,EAAE,GAAG,EAAE;IAC7C,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QAC/D,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,EAAC,GAAG,EAAE,CAAC,EAAC;KACd,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@ -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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,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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|
|||
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@ -1,31 +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 subduxUpreducer: Upreducer<any>;
|
||||
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>, isSink?: boolean): 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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,CAAC,CAAC;aAqBpC,eAAe;aA6Bf,WAAW,EAAI,MAAM,wBAAwB,CAAC,CAAC,CAAC;aAiB1D,KAAK,EAAI,GAAG,CAAC,CAAC,CAAC;IAyBnB,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,EACxE,MAAM,CAAC,EAAE,OAAO;CAQnB;AAED,eAAe,KAAK,CAAC"}
|
|
@ -1,105 +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 subduxUpreducer() {
|
||||
return buildUpreducer_1.default(this.initial, buildMutations_1.default({}, 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, isSink) {
|
||||
this.localActions[creator.type] = creator;
|
||||
this.localMutations[creator.type] = [
|
||||
this.groomMutations(mutation),
|
||||
isSink,
|
||||
];
|
||||
}
|
||||
}
|
||||
__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, "subduxUpreducer", 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":";;;;;;;;;;;AAAA,mDAA2B;AAE3B,+BAAgD;AAEhD,kEAA0C;AAC1C,kEAA0C;AAC1C,sEAA8C;AAE9C,0EAAkD;AAClD,wEAAgD;AAChD,sEAA8C;AAY9C,+CAA6C;AAArC,uCAAA,aAAa,CAAA;AA4BrB,MAAa,KAAK;IA2DhB,YAAY,SAAsB,EAAE;QAClC,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,IAAI,CAAC,CAAC,CAAc,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;QAEvE,IAAI,CAAC,QAAQ,GAAG,YAAE,CAAC,SAAS,CAAC,CAAC,KAA0B,EAAE,EAAE,CAC1D,YAAE,CAAC,aA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CAAC;IACJ,CAAC;IAcD,WAAW,CACT,OAAU,EACV,QAAwE,EACxE,MAAgB;QAEhB,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;QAC1C,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG;YAClC,IAAI,CAAC,cAAc,CAAC,QAAe,CAAgB;YACnD,MAAM;SACP,CAAC;IACJ,CAAC;CACF;AA9La;IAAX,iBAAU;2CAET;AAEU;IAAX,iBAAU;2CAAiD;AAEhD;IAAX,iBAAU;6CAET;AA4BQ;IAAT,eAAQ;uCAMR;AAgBS;IAAT,eAAQ;oCAUR;AAES;IAAT,eAAQ;sCAER;AAMS;IAAT,eAAQ;oCAER;AAOS;IAAT,eAAQ;sCAER;AAmBS;IAAT,eAAQ;4CAER;AA2BS;IAAT,eAAQ;wCASR;AAnMH,sBA+OC;AAED,kBAAe,KAAK,CAAC"}
|
|
@ -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
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue