Compare commits
108 Commits
v2.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 |
|
@ -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: {
|
||||
// ...
|
||||
},
|
||||
};
|
32
.eslintrc.js
|
@ -1,32 +0,0 @@
|
|||
// @format
|
||||
|
||||
// https://dev.to/robertcoopercode/using-eslint-and-prettier-in-a-typescript-project-53jb
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
const ts_nope = [
|
||||
'no-explicit-any',
|
||||
'explicit-function-return-type',
|
||||
'no-object-literal-type-assertion',
|
||||
'camelcase',
|
||||
'member-delimiter-style',
|
||||
'prefer-interface',
|
||||
'indent',
|
||||
].map(r => '@typescript-eslint/' + r);
|
||||
|
||||
module.exports = {
|
||||
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
|
||||
extends: [
|
||||
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
|
||||
],
|
||||
plugins: ['import'],
|
||||
parserOptions: {
|
||||
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
|
||||
sourceType: 'module', // Allows for the use of imports
|
||||
},
|
||||
rules: {
|
||||
..._.fromPairs(ts_nope.map(r => [r, 'off'])),
|
||||
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
|
||||
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
|
||||
},
|
||||
};
|
|
@ -6,7 +6,6 @@ package-lock.json
|
|||
yarn.lock
|
||||
.nyc_output/
|
||||
pnpm-debug.log
|
||||
pnpm-lock.yaml
|
||||
yarn-error.log
|
||||
GPUCache/
|
||||
updux-2.0.0.tgz
|
||||
|
|
|
@ -13,3 +13,6 @@ 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: ''
|
|
@ -1,2 +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
|
@ -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
|
||||
|
|
71
CHANGELOG.md
|
@ -2,29 +2,68 @@
|
|||
|
||||
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.
|
||||
|
||||
## [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)
|
||||
|
||||
## 4.0.0 (2022-08-30)
|
||||
|
||||
### ⚠ BREAKING CHANGES
|
||||
|
||||
* use ts-action for action creation
|
||||
* middleware support refined
|
||||
- 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
|
||||
|
||||
* 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))
|
||||
- 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))
|
||||
- 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.
|
||||
|
|
|
@ -17,24 +17,24 @@ diverse, inclusive, and healthy community.
|
|||
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
|
||||
- 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
|
||||
- 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
|
||||
|
||||
|
@ -106,7 +106,7 @@ 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
|
||||
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
|
||||
|
@ -126,4 +126,3 @@ enforcement ladder](https://github.com/mozilla/diversity).
|
|||
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.
|
||||
|
||||
|
|
27
Changes
|
@ -1,27 +0,0 @@
|
|||
# Revision history for Updux
|
||||
|
||||
NEXT
|
||||
- Mutations passed to the constructor can be arrays of arrays.
|
||||
|
||||
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.
|
32
Promake
|
@ -1,32 +0,0 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const Promake = require('promake');
|
||||
const glob = require('glob').sync;
|
||||
|
||||
const {
|
||||
task, cli, rule, exec
|
||||
} = new Promake();
|
||||
|
||||
|
||||
|
||||
const compile = task( 'compile', rule( 'tsconfig.tsbuildinfo', glob('src/**.ts'),
|
||||
async () => {
|
||||
return exec( 'tsc' );
|
||||
}) );
|
||||
|
||||
const docs = task( 'docs', [ rule(
|
||||
glob('docs/4-API/*.md'),
|
||||
[ ...glob('./src/**.ts'), compile ], async() => {
|
||||
await exec( "typedoc src" );
|
||||
}
|
||||
)]);
|
||||
|
||||
const sidebar = task(
|
||||
'sidebar',
|
||||
rule('./docs/_sidebar.md', [...glob('./docs/4-API/**.md'), docs], async () => {
|
||||
return exec('docsify-auto-sidebar -d docs');
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
cli();
|
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,369 +0,0 @@
|
|||
/**
|
||||
* Config file for API Extractor. For more info, please visit: https://api-extractor.com
|
||||
*/
|
||||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
||||
|
||||
/**
|
||||
* Optionally specifies another JSON config file that this file extends from. This provides a way for
|
||||
* standard settings to be shared across multiple projects.
|
||||
*
|
||||
* If the path starts with "./" or "../", the path is resolved relative to the folder of the file that contains
|
||||
* the "extends" field. Otherwise, the first path segment is interpreted as an NPM package name, and will be
|
||||
* resolved using NodeJS require().
|
||||
*
|
||||
* SUPPORTED TOKENS: none
|
||||
* DEFAULT VALUE: ""
|
||||
*/
|
||||
// "extends": "./shared/api-extractor-base.json"
|
||||
// "extends": "my-package/include/api-extractor-base.json"
|
||||
|
||||
/**
|
||||
* Determines the "<projectFolder>" token that can be used with other config file settings. The project folder
|
||||
* typically contains the tsconfig.json and package.json config files, but the path is user-defined.
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting.
|
||||
*
|
||||
* The default value for "projectFolder" is the token "<lookup>", which means the folder is determined by traversing
|
||||
* parent folders, starting from the folder containing api-extractor.json, and stopping at the first folder
|
||||
* that contains a tsconfig.json file. If a tsconfig.json file cannot be found in this way, then an error
|
||||
* will be reported.
|
||||
*
|
||||
* SUPPORTED TOKENS: <lookup>
|
||||
* DEFAULT VALUE: "<lookup>"
|
||||
*/
|
||||
// "projectFolder": "..",
|
||||
|
||||
/**
|
||||
* (REQUIRED) Specifies the .d.ts file to be used as the starting point for analysis. API Extractor
|
||||
* analyzes the symbols exported by this module.
|
||||
*
|
||||
* The file extension must be ".d.ts" and not ".ts".
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
|
||||
* prepend a folder token such as "<projectFolder>".
|
||||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
*/
|
||||
"mainEntryPointFilePath": "./dist/index.d.ts",
|
||||
|
||||
/**
|
||||
* A list of NPM package names whose exports should be treated as part of this package.
|
||||
*
|
||||
* For example, suppose that Webpack is used to generate a distributed bundle for the project "library1",
|
||||
* and another NPM package "library2" is embedded in this bundle. Some types from library2 may become part
|
||||
* of the exported API for library1, but by default API Extractor would generate a .d.ts rollup that explicitly
|
||||
* imports library2. To avoid this, we can specify:
|
||||
*
|
||||
* "bundledPackages": [ "library2" ],
|
||||
*
|
||||
* This would direct API Extractor to embed those types directly in the .d.ts rollup, as if they had been
|
||||
* local files for library1.
|
||||
*/
|
||||
"bundledPackages": [ ],
|
||||
|
||||
/**
|
||||
* Determines how the TypeScript compiler engine will be invoked by API Extractor.
|
||||
*/
|
||||
"compiler": {
|
||||
/**
|
||||
* Specifies the path to the tsconfig.json file to be used by API Extractor when analyzing the project.
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
|
||||
* prepend a folder token such as "<projectFolder>".
|
||||
*
|
||||
* Note: This setting will be ignored if "overrideTsconfig" is used.
|
||||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
* DEFAULT VALUE: "<projectFolder>/tsconfig.json"
|
||||
*/
|
||||
// "tsconfigFilePath": "<projectFolder>/tsconfig.json",
|
||||
|
||||
/**
|
||||
* Provides a compiler configuration that will be used instead of reading the tsconfig.json file from disk.
|
||||
* The object must conform to the TypeScript tsconfig schema:
|
||||
*
|
||||
* http://json.schemastore.org/tsconfig
|
||||
*
|
||||
* If omitted, then the tsconfig.json file will be read from the "projectFolder".
|
||||
*
|
||||
* DEFAULT VALUE: no overrideTsconfig section
|
||||
*/
|
||||
// "overrideTsconfig": {
|
||||
// . . .
|
||||
// }
|
||||
|
||||
/**
|
||||
* This option causes the compiler to be invoked with the --skipLibCheck option. This option is not recommended
|
||||
* and may cause API Extractor to produce incomplete or incorrect declarations, but it may be required when
|
||||
* dependencies contain declarations that are incompatible with the TypeScript engine that API Extractor uses
|
||||
* for its analysis. Where possible, the underlying issue should be fixed rather than relying on skipLibCheck.
|
||||
*
|
||||
* DEFAULT VALUE: false
|
||||
*/
|
||||
// "skipLibCheck": true,
|
||||
},
|
||||
|
||||
/**
|
||||
* Configures how the API report file (*.api.md) will be generated.
|
||||
*/
|
||||
"apiReport": {
|
||||
/**
|
||||
* (REQUIRED) Whether to generate an API report.
|
||||
*/
|
||||
"enabled": true,
|
||||
|
||||
/**
|
||||
* The filename for the API report files. It will be combined with "reportFolder" or "reportTempFolder" to produce
|
||||
* a full file path.
|
||||
*
|
||||
* The file extension should be ".api.md", and the string should not contain a path separator such as "\" or "/".
|
||||
*
|
||||
* SUPPORTED TOKENS: <packageName>, <unscopedPackageName>
|
||||
* DEFAULT VALUE: "<unscopedPackageName>.api.md"
|
||||
*/
|
||||
// "reportFileName": "<unscopedPackageName>.api.md",
|
||||
|
||||
/**
|
||||
* Specifies the folder where the API report file is written. The file name portion is determined by
|
||||
* the "reportFileName" setting.
|
||||
*
|
||||
* The API report file is normally tracked by Git. Changes to it can be used to trigger a branch policy,
|
||||
* e.g. for an API review.
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
|
||||
* prepend a folder token such as "<projectFolder>".
|
||||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
* DEFAULT VALUE: "<projectFolder>/etc/"
|
||||
*/
|
||||
"reportFolder": "<projectFolder>/temp/",
|
||||
|
||||
/**
|
||||
* Specifies the folder where the temporary report file is written. The file name portion is determined by
|
||||
* the "reportFileName" setting.
|
||||
*
|
||||
* After the temporary file is written to disk, it is compared with the file in the "reportFolder".
|
||||
* If they are different, a production build will fail.
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
|
||||
* prepend a folder token such as "<projectFolder>".
|
||||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
* DEFAULT VALUE: "<projectFolder>/temp/"
|
||||
*/
|
||||
"reportTempFolder": "<projectFolder>/temp/"
|
||||
},
|
||||
|
||||
/**
|
||||
* Configures how the doc model file (*.api.json) will be generated.
|
||||
*/
|
||||
"docModel": {
|
||||
/**
|
||||
* (REQUIRED) Whether to generate a doc model file.
|
||||
*/
|
||||
"enabled": true,
|
||||
|
||||
/**
|
||||
* The output path for the doc model file. The file extension should be ".api.json".
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
|
||||
* prepend a folder token such as "<projectFolder>".
|
||||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
* DEFAULT VALUE: "<projectFolder>/temp/<unscopedPackageName>.api.json"
|
||||
*/
|
||||
// "apiJsonFilePath": "<projectFolder>/temp/<unscopedPackageName>.api.json"
|
||||
},
|
||||
|
||||
/**
|
||||
* Configures how the .d.ts rollup file will be generated.
|
||||
*/
|
||||
"dtsRollup": {
|
||||
/**
|
||||
* (REQUIRED) Whether to generate the .d.ts rollup file.
|
||||
*/
|
||||
"enabled": true,
|
||||
|
||||
/**
|
||||
* Specifies the output path for a .d.ts rollup file to be generated without any trimming.
|
||||
* This file will include all declarations that are exported by the main entry point.
|
||||
*
|
||||
* If the path is an empty string, then this file will not be written.
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
|
||||
* prepend a folder token such as "<projectFolder>".
|
||||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
* DEFAULT VALUE: "<projectFolder>/dist/<unscopedPackageName>.d.ts"
|
||||
*/
|
||||
// "untrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>.d.ts",
|
||||
|
||||
/**
|
||||
* Specifies the output path for a .d.ts rollup file to be generated with trimming for a "beta" release.
|
||||
* This file will include only declarations that are marked as "@public" or "@beta".
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
|
||||
* prepend a folder token such as "<projectFolder>".
|
||||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
* DEFAULT VALUE: ""
|
||||
*/
|
||||
// "betaTrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>-beta.d.ts",
|
||||
|
||||
|
||||
/**
|
||||
* Specifies the output path for a .d.ts rollup file to be generated with trimming for a "public" release.
|
||||
* This file will include only declarations that are marked as "@public".
|
||||
*
|
||||
* If the path is an empty string, then this file will not be written.
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
|
||||
* prepend a folder token such as "<projectFolder>".
|
||||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
* DEFAULT VALUE: ""
|
||||
*/
|
||||
// "publicTrimmedFilePath": "<projectFolder>/dist/<unscopedPackageName>-public.d.ts",
|
||||
|
||||
/**
|
||||
* When a declaration is trimmed, by default it will be replaced by a code comment such as
|
||||
* "Excluded from this release type: exampleMember". Set "omitTrimmingComments" to true to remove the
|
||||
* declaration completely.
|
||||
*
|
||||
* DEFAULT VALUE: false
|
||||
*/
|
||||
// "omitTrimmingComments": true
|
||||
},
|
||||
|
||||
/**
|
||||
* Configures how the tsdoc-metadata.json file will be generated.
|
||||
*/
|
||||
"tsdocMetadata": {
|
||||
/**
|
||||
* Whether to generate the tsdoc-metadata.json file.
|
||||
*
|
||||
* DEFAULT VALUE: true
|
||||
*/
|
||||
// "enabled": true,
|
||||
|
||||
/**
|
||||
* Specifies where the TSDoc metadata file should be written.
|
||||
*
|
||||
* The path is resolved relative to the folder of the config file that contains the setting; to change this,
|
||||
* prepend a folder token such as "<projectFolder>".
|
||||
*
|
||||
* The default value is "<lookup>", which causes the path to be automatically inferred from the "tsdocMetadata",
|
||||
* "typings" or "main" fields of the project's package.json. If none of these fields are set, the lookup
|
||||
* falls back to "tsdoc-metadata.json" in the package folder.
|
||||
*
|
||||
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
|
||||
* DEFAULT VALUE: "<lookup>"
|
||||
*/
|
||||
// "tsdocMetadataFilePath": "<projectFolder>/dist/tsdoc-metadata.json"
|
||||
},
|
||||
|
||||
/**
|
||||
* Specifies what type of newlines API Extractor should use when writing output files. By default, the output files
|
||||
* will be written with Windows-style newlines. To use POSIX-style newlines, specify "lf" instead.
|
||||
* To use the OS's default newline kind, specify "os".
|
||||
*
|
||||
* DEFAULT VALUE: "crlf"
|
||||
*/
|
||||
// "newlineKind": "crlf",
|
||||
|
||||
/**
|
||||
* Configures how API Extractor reports error and warning messages produced during analysis.
|
||||
*
|
||||
* There are three sources of messages: compiler messages, API Extractor messages, and TSDoc messages.
|
||||
*/
|
||||
"messages": {
|
||||
/**
|
||||
* Configures handling of diagnostic messages reported by the TypeScript compiler engine while analyzing
|
||||
* the input .d.ts files.
|
||||
*
|
||||
* TypeScript message identifiers start with "TS" followed by an integer. For example: "TS2551"
|
||||
*
|
||||
* DEFAULT VALUE: A single "default" entry with logLevel=warning.
|
||||
*/
|
||||
"compilerMessageReporting": {
|
||||
/**
|
||||
* Configures the default routing for messages that don't match an explicit rule in this table.
|
||||
*/
|
||||
"default": {
|
||||
/**
|
||||
* Specifies whether the message should be written to the the tool's output log. Note that
|
||||
* the "addToApiReportFile" property may supersede this option.
|
||||
*
|
||||
* Possible values: "error", "warning", "none"
|
||||
*
|
||||
* Errors cause the build to fail and return a nonzero exit code. Warnings cause a production build fail
|
||||
* and return a nonzero exit code. For a non-production build (e.g. when "api-extractor run" includes
|
||||
* the "--local" option), the warning is displayed but the build will not fail.
|
||||
*
|
||||
* DEFAULT VALUE: "warning"
|
||||
*/
|
||||
"logLevel": "warning",
|
||||
|
||||
/**
|
||||
* When addToApiReportFile is true: If API Extractor is configured to write an API report file (.api.md),
|
||||
* then the message will be written inside that file; otherwise, the message is instead logged according to
|
||||
* the "logLevel" option.
|
||||
*
|
||||
* DEFAULT VALUE: false
|
||||
*/
|
||||
// "addToApiReportFile": false
|
||||
},
|
||||
|
||||
// "TS2551": {
|
||||
// "logLevel": "warning",
|
||||
// "addToApiReportFile": true
|
||||
// },
|
||||
//
|
||||
// . . .
|
||||
},
|
||||
|
||||
/**
|
||||
* Configures handling of messages reported by API Extractor during its analysis.
|
||||
*
|
||||
* API Extractor message identifiers start with "ae-". For example: "ae-extra-release-tag"
|
||||
*
|
||||
* DEFAULT VALUE: See api-extractor-defaults.json for the complete table of extractorMessageReporting mappings
|
||||
*/
|
||||
"extractorMessageReporting": {
|
||||
"default": {
|
||||
"logLevel": "warning",
|
||||
// "addToApiReportFile": false
|
||||
},
|
||||
|
||||
// "ae-extra-release-tag": {
|
||||
// "logLevel": "warning",
|
||||
// "addToApiReportFile": true
|
||||
// },
|
||||
//
|
||||
// . . .
|
||||
},
|
||||
|
||||
/**
|
||||
* Configures handling of messages reported by the TSDoc parser when analyzing code comments.
|
||||
*
|
||||
* TSDoc message identifiers start with "tsdoc-". For example: "tsdoc-link-tag-unescaped-text"
|
||||
*
|
||||
* DEFAULT VALUE: A single "default" entry with logLevel=warning.
|
||||
*/
|
||||
"tsdocMessageReporting": {
|
||||
"default": {
|
||||
"logLevel": "warning",
|
||||
// "addToApiReportFile": false
|
||||
}
|
||||
|
||||
// "tsdoc-link-tag-unescaped-text": {
|
||||
// "logLevel": "warning",
|
||||
// "addToApiReportFile": true
|
||||
// },
|
||||
//
|
||||
// . . .
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
module.exports = {
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
targets: {
|
||||
node: 'current',
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
|
@ -1,228 +0,0 @@
|
|||
[updux - v1.2.0](README.md) › [Globals](globals.md)
|
||||
|
||||
# updux - v1.2.0
|
||||
|
||||
# What's Updux?
|
||||
|
||||
So, I'm a fan of [Redux](https://redux.js.org). Two days ago I discovered
|
||||
[rematch](https://rematch.github.io/rematch) alonside a few other frameworks built atop Redux.
|
||||
|
||||
It has a couple of pretty good ideas that removes some of the
|
||||
boilerplate. Keeping mutations and asynchronous effects close to the
|
||||
reducer definition? Nice. Automatically infering the
|
||||
actions from the said mutations and effects? Genius!
|
||||
|
||||
But it also enforces a flat hierarchy of reducers -- where
|
||||
is the fun in that? And I'm also having a strong love for
|
||||
[Updeep](https://github.com/substantial/updeep), so I want reducer state updates to leverage the heck out of it.
|
||||
|
||||
All that to say, say hello to `Updux`. Heavily inspired by `rematch`, but twisted
|
||||
to work with `updeep` and to fit my peculiar needs. It offers features such as
|
||||
|
||||
* Mimic the way VueX has mutations (reducer reactions to specific actions) and
|
||||
effects (middleware reacting to actions that can be asynchronous and/or
|
||||
have side-effects), so everything pertaining to a store are all defined
|
||||
in the space place.
|
||||
* Automatically gather all actions used by the updux's effects and mutations,
|
||||
and makes then accessible as attributes to the `dispatch` object of the
|
||||
store.
|
||||
* Mutations have a signature that is friendly to Updux and Immer.
|
||||
* Also, the mutation signature auto-unwrap the payload of the actions for you.
|
||||
* TypeScript types.
|
||||
|
||||
Fair warning: this package is still very new, probably very buggy,
|
||||
definitively very badly documented, and very subject to changes. Caveat
|
||||
Maxima Emptor.
|
||||
|
||||
# Synopsis
|
||||
|
||||
```
|
||||
import updux from 'updux';
|
||||
|
||||
import otherUpdux from './otherUpdux';
|
||||
|
||||
const {
|
||||
initial,
|
||||
reducer,
|
||||
actions,
|
||||
middleware,
|
||||
createStore,
|
||||
} = new Updux({
|
||||
initial: {
|
||||
counter: 0,
|
||||
},
|
||||
subduxes: {
|
||||
otherUpdux,
|
||||
},
|
||||
mutations: {
|
||||
inc: ( increment = 1 ) => u({counter: s => s + increment })
|
||||
},
|
||||
effects: {
|
||||
'*' => api => next => action => {
|
||||
console.log( "hey, look, an action zoomed by!", action );
|
||||
next(action);
|
||||
};
|
||||
},
|
||||
actions: {
|
||||
customAction: ( someArg ) => ({
|
||||
type: "custom",
|
||||
payload: { someProp: someArg }
|
||||
}),
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
const store = createStore();
|
||||
|
||||
store.dispatch.inc(3);
|
||||
```
|
||||
|
||||
# Description
|
||||
|
||||
Full documentation can be [found here](https://yanick.github.io/updux/docs/).
|
||||
|
||||
## Exporting upduxes
|
||||
|
||||
If you are creating upduxes that will be used as subduxes
|
||||
by other upduxes, or as
|
||||
[ducks](https://github.com/erikras/ducks-modular-redux)-like containers, I
|
||||
recommend that you export the Updux instance as the default export:
|
||||
|
||||
```
|
||||
import Updux from 'updux';
|
||||
|
||||
const updux = new Updux({ ... });
|
||||
|
||||
export default updux;
|
||||
```
|
||||
|
||||
Then you can use them as subduxes like this:
|
||||
|
||||
```
|
||||
import Updux from 'updux';
|
||||
import foo from './foo'; // foo is an Updux
|
||||
import bar from './bar'; // bar is an Updux as well
|
||||
|
||||
const updux = new Updux({
|
||||
subduxes: {
|
||||
foo, bar
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Or if you want to use it:
|
||||
|
||||
```
|
||||
import updux from './myUpdux';
|
||||
|
||||
const {
|
||||
reducer,
|
||||
actions: { doTheThing },
|
||||
createStore,
|
||||
middleware,
|
||||
} = updux;
|
||||
```
|
||||
|
||||
## Mapping a mutation to all values of a state
|
||||
|
||||
Say you have a `todos` state that is an array of `todo` sub-states. It's easy
|
||||
enough to have the main reducer maps away all items to the sub-reducer:
|
||||
|
||||
```
|
||||
const todo = new Updux({
|
||||
mutations: {
|
||||
review: () => u({ reviewed: true}),
|
||||
done: () => u({done: true}),
|
||||
},
|
||||
});
|
||||
|
||||
const todos = new Updux({ initial: [] });
|
||||
|
||||
todos.addMutation(
|
||||
todo.actions.review,
|
||||
(_,action) => state => state.map( todo.upreducer(action) )
|
||||
);
|
||||
todos.addMutation(
|
||||
todo.actions.done,
|
||||
(id,action) => u.map(u.if(u.is('id',id), todo.upreducer(action))),
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
But `updeep` can iterate through all the items of an array (or the values of
|
||||
an object) via the special key `*`. So the todos updux above could also be
|
||||
written:
|
||||
|
||||
```
|
||||
const todo = new Updux({
|
||||
mutations: {
|
||||
review: () => u({ reviewed: true}),
|
||||
done: () => u({done: true}),
|
||||
},
|
||||
});
|
||||
|
||||
const todos = new Updux({
|
||||
subduxes: { '*': todo },
|
||||
});
|
||||
|
||||
todos.addMutation(
|
||||
todo.actions.done,
|
||||
(id,action) => u.map(u.if(u.is('id',id), todo.upreducer(action))),
|
||||
true
|
||||
);
|
||||
```
|
||||
|
||||
The advantages being that the actions/mutations/effects of the subdux will be
|
||||
imported by the root updux as usual, and all actions that aren't being
|
||||
overridden by a sink mutation will trickle down automatically.
|
||||
|
||||
## Usage with Immer
|
||||
|
||||
While Updux was created with Updeep in mind, it also plays very
|
||||
well with [Immer](https://immerjs.github.io/immer/docs/introduction).
|
||||
|
||||
For example, taking this basic updux:
|
||||
|
||||
```
|
||||
import Updux from 'updux';
|
||||
|
||||
const updux = new Updux({
|
||||
initial: { counter: 0 },
|
||||
mutations: {
|
||||
add: (inc=1) => state => { counter: counter + inc }
|
||||
}
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
Converting it to Immer would look like:
|
||||
|
||||
```
|
||||
import Updux from 'updux';
|
||||
import { produce } from 'Immer';
|
||||
|
||||
const updux = new Updux({
|
||||
initial: { counter: 0 },
|
||||
mutations: {
|
||||
add: (inc=1) => produce( draft => draft.counter += inc ) }
|
||||
}
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
But since typing `produce` over and over is no fun, `groomMutations`
|
||||
can be used to wrap all mutations with it:
|
||||
|
||||
```
|
||||
import Updux from 'updux';
|
||||
import { produce } from 'Immer';
|
||||
|
||||
const updux = new Updux({
|
||||
initial: { counter: 0 },
|
||||
groomMutations: mutation => (...args) => produce( mutation(...args) ),
|
||||
mutations: {
|
||||
add: (inc=1) => draft => draft.counter += inc
|
||||
}
|
||||
});
|
||||
|
||||
```
|
|
@ -1,491 +0,0 @@
|
|||
[updux - v1.2.0](../README.md) › [Globals](../globals.md) › [Updux](updux.md)
|
||||
|
||||
# Class: Updux <**S, A, X, C**>
|
||||
|
||||
## Type parameters
|
||||
|
||||
▪ **S**
|
||||
|
||||
▪ **A**
|
||||
|
||||
▪ **X**
|
||||
|
||||
▪ **C**: *[UpduxConfig](../globals.md#upduxconfig)*
|
||||
|
||||
## Hierarchy
|
||||
|
||||
* **Updux**
|
||||
|
||||
## Index
|
||||
|
||||
### Constructors
|
||||
|
||||
* [constructor](updux.md#constructor)
|
||||
|
||||
### Properties
|
||||
|
||||
* [coduxes](updux.md#coduxes)
|
||||
* [groomMutations](updux.md#groommutations)
|
||||
* [subduxes](updux.md#subduxes)
|
||||
|
||||
### Accessors
|
||||
|
||||
* [_middlewareEntries](updux.md#_middlewareentries)
|
||||
* [actions](updux.md#actions)
|
||||
* [asDux](updux.md#asdux)
|
||||
* [createStore](updux.md#createstore)
|
||||
* [initial](updux.md#initial)
|
||||
* [middleware](updux.md#middleware)
|
||||
* [mutations](updux.md#mutations)
|
||||
* [reducer](updux.md#reducer)
|
||||
* [selectors](updux.md#selectors)
|
||||
* [subduxUpreducer](updux.md#subduxupreducer)
|
||||
* [upreducer](updux.md#upreducer)
|
||||
|
||||
### Methods
|
||||
|
||||
* [addAction](updux.md#addaction)
|
||||
* [addEffect](updux.md#addeffect)
|
||||
* [addMutation](updux.md#addmutation)
|
||||
* [addSelector](updux.md#addselector)
|
||||
|
||||
## Constructors
|
||||
|
||||
### constructor
|
||||
|
||||
\+ **new Updux**(`config`: C): *[Updux](updux.md)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type | Default | Description |
|
||||
------ | ------ | ------ | ------ |
|
||||
`config` | C | {} as C | an [UpduxConfig](../globals.md#upduxconfig) plain object |
|
||||
|
||||
**Returns:** *[Updux](updux.md)*
|
||||
|
||||
## Properties
|
||||
|
||||
### coduxes
|
||||
|
||||
• **coduxes**: *[Dux](../globals.md#dux)[]*
|
||||
|
||||
___
|
||||
|
||||
### groomMutations
|
||||
|
||||
• **groomMutations**: *function*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
▸ (`mutation`: [Mutation](../globals.md#mutation)‹S›): *[Mutation](../globals.md#mutation)‹S›*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`mutation` | [Mutation](../globals.md#mutation)‹S› |
|
||||
|
||||
___
|
||||
|
||||
### subduxes
|
||||
|
||||
• **subduxes**: *[Dictionary](../globals.md#dictionary)‹[Dux](../globals.md#dux)›*
|
||||
|
||||
## Accessors
|
||||
|
||||
### _middlewareEntries
|
||||
|
||||
• **get _middlewareEntries**(): *any[]*
|
||||
|
||||
**Returns:** *any[]*
|
||||
|
||||
___
|
||||
|
||||
### actions
|
||||
|
||||
• **get actions**(): *[DuxActions](../globals.md#duxactions)‹A, C›*
|
||||
|
||||
Action creators for all actions defined or used in the actions, mutations, effects and subduxes
|
||||
of the updux config.
|
||||
|
||||
Non-custom action creators defined in `actions` have the signature `(payload={},meta={}) => ({type,
|
||||
payload,meta})` (with the extra sugar that if `meta` or `payload` are not
|
||||
specified, that key won't be present in the produced action).
|
||||
|
||||
The same action creator can be included
|
||||
in multiple subduxes. However, if two different creators
|
||||
are included for the same action, an error will be thrown.
|
||||
|
||||
**`example`**
|
||||
|
||||
```
|
||||
const actions = updux.actions;
|
||||
```
|
||||
|
||||
**Returns:** *[DuxActions](../globals.md#duxactions)‹A, C›*
|
||||
|
||||
___
|
||||
|
||||
### asDux
|
||||
|
||||
• **get asDux**(): *object*
|
||||
|
||||
Returns a <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.
|
||||
|
||||
**`example`**
|
||||
|
||||
```
|
||||
const {
|
||||
createStore,
|
||||
upreducer,
|
||||
subduxes,
|
||||
coduxes,
|
||||
middleware,
|
||||
actions,
|
||||
reducer,
|
||||
mutations,
|
||||
initial,
|
||||
selectors,
|
||||
} = myUpdux.asDux;
|
||||
```
|
||||
|
||||
**Returns:** *object*
|
||||
|
||||
* **actions**: = this.actions
|
||||
|
||||
* **coduxes**: *object[]* = this.coduxes
|
||||
|
||||
* **createStore**(): *function*
|
||||
|
||||
* (`initial?`: S, `injectEnhancer?`: Function): *Store‹S› & object*
|
||||
|
||||
* **initial**: = this.initial
|
||||
|
||||
* **middleware**(): *function*
|
||||
|
||||
* (`api`: UpduxMiddlewareAPI‹S, X›): *function*
|
||||
|
||||
* (`next`: Function): *function*
|
||||
|
||||
* (`action`: A): *any*
|
||||
|
||||
* **mutations**(): *object*
|
||||
|
||||
* **reducer**(): *function*
|
||||
|
||||
* (`state`: S | undefined, `action`: [Action](../globals.md#action)): *S*
|
||||
|
||||
* **selectors**: = this.selectors
|
||||
|
||||
* **subduxes**(): *object*
|
||||
|
||||
* **upreducer**(): *function*
|
||||
|
||||
* (`action`: [Action](../globals.md#action)): *function*
|
||||
|
||||
* (`state`: S): *S*
|
||||
|
||||
___
|
||||
|
||||
### createStore
|
||||
|
||||
• **get createStore**(): *function*
|
||||
|
||||
Returns a `createStore` function that takes two argument:
|
||||
`initial` and `injectEnhancer`. `initial` is a custom
|
||||
initial state for the store, and `injectEnhancer` is a function
|
||||
taking in the middleware built by the updux object and allowing
|
||||
you to wrap it in any enhancer you want.
|
||||
|
||||
**`example`**
|
||||
|
||||
```
|
||||
const createStore = updux.createStore;
|
||||
|
||||
const store = createStore(initial);
|
||||
```
|
||||
|
||||
**Returns:** *function*
|
||||
|
||||
▸ (`initial?`: S, `injectEnhancer?`: Function): *Store‹S› & object*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`initial?` | S |
|
||||
`injectEnhancer?` | Function |
|
||||
|
||||
___
|
||||
|
||||
### initial
|
||||
|
||||
• **get initial**(): *AggDuxState‹S, C›*
|
||||
|
||||
**Returns:** *AggDuxState‹S, C›*
|
||||
|
||||
___
|
||||
|
||||
### middleware
|
||||
|
||||
• **get middleware**(): *[UpduxMiddleware](../globals.md#upduxmiddleware)‹AggDuxState‹S, C›, [DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C››*
|
||||
|
||||
Array of middlewares aggregating all the effects defined in the
|
||||
updux and its subduxes. Effects of the updux itself are
|
||||
done before the subduxes effects.
|
||||
Note that `getState` will always return the state of the
|
||||
local updux.
|
||||
|
||||
**`example`**
|
||||
|
||||
```
|
||||
const middleware = updux.middleware;
|
||||
```
|
||||
|
||||
**Returns:** *[UpduxMiddleware](../globals.md#upduxmiddleware)‹AggDuxState‹S, C›, [DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C››*
|
||||
|
||||
___
|
||||
|
||||
### mutations
|
||||
|
||||
• **get mutations**(): *[Dictionary](../globals.md#dictionary)‹[Mutation](../globals.md#mutation)‹S››*
|
||||
|
||||
Merge of the updux and subduxes mutations. If an action triggers
|
||||
mutations in both the main updux and its subduxes, the subduxes
|
||||
mutations will be performed first.
|
||||
|
||||
**Returns:** *[Dictionary](../globals.md#dictionary)‹[Mutation](../globals.md#mutation)‹S››*
|
||||
|
||||
___
|
||||
|
||||
### reducer
|
||||
|
||||
• **get reducer**(): *function*
|
||||
|
||||
A Redux reducer generated using the computed initial state and
|
||||
mutations.
|
||||
|
||||
**Returns:** *function*
|
||||
|
||||
▸ (`state`: S | undefined, `action`: [Action](../globals.md#action)): *S*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`state` | S | undefined |
|
||||
`action` | [Action](../globals.md#action) |
|
||||
|
||||
___
|
||||
|
||||
### selectors
|
||||
|
||||
• **get selectors**(): *[DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C›*
|
||||
|
||||
A dictionary of the updux's selectors. Subduxes'
|
||||
selectors are included as well (with the mapping to the
|
||||
sub-state already taken care of you).
|
||||
|
||||
**Returns:** *[DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C›*
|
||||
|
||||
___
|
||||
|
||||
### subduxUpreducer
|
||||
|
||||
• **get subduxUpreducer**(): *function*
|
||||
|
||||
Returns the upreducer made of the merge of all sudbuxes reducers, without
|
||||
the local mutations. Useful, for example, for sink mutations.
|
||||
|
||||
**`example`**
|
||||
|
||||
```
|
||||
import todo from './todo'; // updux for a single todo
|
||||
import Updux from 'updux';
|
||||
import u from 'updeep';
|
||||
|
||||
const todos = new Updux({ initial: [], subduxes: { '*': todo } });
|
||||
todos.addMutation(
|
||||
todo.actions.done,
|
||||
({todo_id},action) => u.map( u.if( u.is('id',todo_id) ), todos.subduxUpreducer(action) )
|
||||
true
|
||||
);
|
||||
```
|
||||
|
||||
**Returns:** *function*
|
||||
|
||||
▸ (`action`: [Action](../globals.md#action)): *function*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`action` | [Action](../globals.md#action) |
|
||||
|
||||
▸ (`state`: S): *S*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`state` | S |
|
||||
|
||||
___
|
||||
|
||||
### upreducer
|
||||
|
||||
• **get upreducer**(): *[Upreducer](../globals.md#upreducer)‹S›*
|
||||
|
||||
**Returns:** *[Upreducer](../globals.md#upreducer)‹S›*
|
||||
|
||||
## Methods
|
||||
|
||||
### addAction
|
||||
|
||||
▸ **addAction**(`theaction`: string, `transform?`: any): *ActionCreator‹string, any›*
|
||||
|
||||
Adds an action to the updux. It can take an already defined action
|
||||
creator, or any arguments that can be passed to `actionCreator`.
|
||||
|
||||
**`example`**
|
||||
```
|
||||
const action = updux.addAction( name, ...creatorArgs );
|
||||
const action = updux.addAction( otherActionCreator );
|
||||
```
|
||||
|
||||
**`example`**
|
||||
```
|
||||
import {actionCreator, Updux} from 'updux';
|
||||
|
||||
const updux = new Updux();
|
||||
|
||||
const foo = updux.addAction('foo');
|
||||
const bar = updux.addAction( 'bar', (x) => ({stuff: x+1}) );
|
||||
|
||||
const baz = actionCreator( 'baz' );
|
||||
|
||||
foo({ a: 1}); // => { type: 'foo', payload: { a: 1 } }
|
||||
bar(2); // => { type: 'bar', payload: { stuff: 3 } }
|
||||
baz(); // => { type: 'baz', payload: undefined }
|
||||
```
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`theaction` | string |
|
||||
`transform?` | any |
|
||||
|
||||
**Returns:** *ActionCreator‹string, any›*
|
||||
|
||||
▸ **addAction**(`theaction`: string | ActionCreator‹any›, `transform?`: undefined): *ActionCreator‹string, any›*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`theaction` | string | ActionCreator‹any› |
|
||||
`transform?` | undefined |
|
||||
|
||||
**Returns:** *ActionCreator‹string, any›*
|
||||
|
||||
___
|
||||
|
||||
### addEffect
|
||||
|
||||
▸ **addEffect**<**AC**>(`creator`: AC, `middleware`: [UpduxMiddleware](../globals.md#upduxmiddleware)‹AggDuxState‹S, C›, [DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C›, ReturnType‹AC››, `isGenerator?`: undefined | false | true): *any*
|
||||
|
||||
**Type parameters:**
|
||||
|
||||
▪ **AC**: *ActionCreator*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`creator` | AC |
|
||||
`middleware` | [UpduxMiddleware](../globals.md#upduxmiddleware)‹AggDuxState‹S, C›, [DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C›, ReturnType‹AC›› |
|
||||
`isGenerator?` | undefined | false | true |
|
||||
|
||||
**Returns:** *any*
|
||||
|
||||
▸ **addEffect**(`creator`: string, `middleware`: [UpduxMiddleware](../globals.md#upduxmiddleware)‹AggDuxState‹S, C›, [DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C››, `isGenerator?`: undefined | false | true): *any*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`creator` | string |
|
||||
`middleware` | [UpduxMiddleware](../globals.md#upduxmiddleware)‹AggDuxState‹S, C›, [DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C›› |
|
||||
`isGenerator?` | undefined | false | true |
|
||||
|
||||
**Returns:** *any*
|
||||
|
||||
___
|
||||
|
||||
### addMutation
|
||||
|
||||
▸ **addMutation**<**A**>(`creator`: A, `mutation`: [Mutation](../globals.md#mutation)‹S, ActionType‹A››, `isSink?`: undefined | false | true): *any*
|
||||
|
||||
Adds a mutation and its associated action to the updux.
|
||||
|
||||
**`remarks`**
|
||||
|
||||
If a local mutation was already associated to the action,
|
||||
it will be replaced by the new one.
|
||||
|
||||
**`example`**
|
||||
|
||||
```js
|
||||
updux.addMutation(
|
||||
action('ADD', payload<int>() ),
|
||||
inc => state => state + in
|
||||
);
|
||||
```
|
||||
|
||||
**Type parameters:**
|
||||
|
||||
▪ **A**: *ActionCreator*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type | Description |
|
||||
------ | ------ | ------ |
|
||||
`creator` | A | - |
|
||||
`mutation` | [Mutation](../globals.md#mutation)‹S, ActionType‹A›› | - |
|
||||
`isSink?` | undefined | false | true | If `true`, disables the subduxes mutations for this action. To conditionally run the subduxes mutations, check out [subduxUpreducer](updux.md#subduxupreducer). Defaults to `false`. |
|
||||
|
||||
**Returns:** *any*
|
||||
|
||||
▸ **addMutation**<**A**>(`creator`: string, `mutation`: [Mutation](../globals.md#mutation)‹S, any›, `isSink?`: undefined | false | true): *any*
|
||||
|
||||
**Type parameters:**
|
||||
|
||||
▪ **A**: *ActionCreator*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`creator` | string |
|
||||
`mutation` | [Mutation](../globals.md#mutation)‹S, any› |
|
||||
`isSink?` | undefined | false | true |
|
||||
|
||||
**Returns:** *any*
|
||||
|
||||
___
|
||||
|
||||
### addSelector
|
||||
|
||||
▸ **addSelector**(`name`: string, `selector`: [Selector](../globals.md#selector)): *void*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`name` | string |
|
||||
`selector` | [Selector](../globals.md#selector) |
|
||||
|
||||
**Returns:** *void*
|
|
@ -1,980 +0,0 @@
|
|||
[updux - v1.2.0](README.md) › [Globals](globals.md)
|
||||
|
||||
# updux - v1.2.0
|
||||
|
||||
## Index
|
||||
|
||||
### Classes
|
||||
|
||||
* [Updux](classes/updux.md)
|
||||
|
||||
### Type aliases
|
||||
|
||||
* [Action](globals.md#action)
|
||||
* [ActionPair](globals.md#actionpair)
|
||||
* [ActionPayloadGenerator](globals.md#actionpayloadgenerator)
|
||||
* [ActionsOf](globals.md#actionsof)
|
||||
* [CoduxesOf](globals.md#coduxesof)
|
||||
* [Dictionary](globals.md#dictionary)
|
||||
* [Dux](globals.md#dux)
|
||||
* [DuxActions](globals.md#duxactions)
|
||||
* [DuxActionsCoduxes](globals.md#duxactionscoduxes)
|
||||
* [DuxActionsSubduxes](globals.md#duxactionssubduxes)
|
||||
* [DuxSelectors](globals.md#duxselectors)
|
||||
* [DuxState](globals.md#duxstate)
|
||||
* [DuxStateCoduxes](globals.md#duxstatecoduxes)
|
||||
* [DuxStateGlobSub](globals.md#duxstateglobsub)
|
||||
* [DuxStateSubduxes](globals.md#duxstatesubduxes)
|
||||
* [Effect](globals.md#effect)
|
||||
* [GenericActions](globals.md#genericactions)
|
||||
* [ItemsOf](globals.md#itemsof)
|
||||
* [LocalDuxState](globals.md#localduxstate)
|
||||
* [MaybePayload](globals.md#maybepayload)
|
||||
* [MaybeReturnType](globals.md#maybereturntype)
|
||||
* [Merge](globals.md#merge)
|
||||
* [Mutation](globals.md#mutation)
|
||||
* [MutationEntry](globals.md#mutationentry)
|
||||
* [MwGen](globals.md#mwgen)
|
||||
* [Next](globals.md#next)
|
||||
* [RebaseSelector](globals.md#rebaseselector)
|
||||
* [Selector](globals.md#selector)
|
||||
* [SelectorsOf](globals.md#selectorsof)
|
||||
* [StateOf](globals.md#stateof)
|
||||
* [StoreWithDispatchActions](globals.md#storewithdispatchactions)
|
||||
* [SubMutations](globals.md#submutations)
|
||||
* [Submws](globals.md#submws)
|
||||
* [UnionToIntersection](globals.md#uniontointersection)
|
||||
* [UpduxActions](globals.md#upduxactions)
|
||||
* [UpduxConfig](globals.md#upduxconfig)
|
||||
* [UpduxLocalActions](globals.md#upduxlocalactions)
|
||||
* [UpduxMiddleware](globals.md#upduxmiddleware)
|
||||
* [Upreducer](globals.md#upreducer)
|
||||
|
||||
### Variables
|
||||
|
||||
* [subEffects](globals.md#const-subeffects)
|
||||
* [updux](globals.md#const-updux)
|
||||
|
||||
### Functions
|
||||
|
||||
* [MiddlewareFor](globals.md#const-middlewarefor)
|
||||
* [buildActions](globals.md#buildactions)
|
||||
* [buildCreateStore](globals.md#buildcreatestore)
|
||||
* [buildInitial](globals.md#buildinitial)
|
||||
* [buildMiddleware](globals.md#buildmiddleware)
|
||||
* [buildMutations](globals.md#buildmutations)
|
||||
* [buildSelectors](globals.md#buildselectors)
|
||||
* [buildUpreducer](globals.md#buildupreducer)
|
||||
* [coduxes](globals.md#const-coduxes)
|
||||
* [composeMutations](globals.md#const-composemutations)
|
||||
* [composeMw](globals.md#const-composemw)
|
||||
* [dux](globals.md#const-dux)
|
||||
* [effectToMw](globals.md#const-effecttomw)
|
||||
* [sliceMw](globals.md#slicemw)
|
||||
* [subMiddleware](globals.md#const-submiddleware)
|
||||
* [subSelectors](globals.md#subselectors)
|
||||
|
||||
## Type aliases
|
||||
|
||||
### Action
|
||||
|
||||
Ƭ **Action**: *object & [MaybePayload](globals.md#maybepayload)‹P›*
|
||||
|
||||
___
|
||||
|
||||
### ActionPair
|
||||
|
||||
Ƭ **ActionPair**: *[string, ActionCreator]*
|
||||
|
||||
___
|
||||
|
||||
### ActionPayloadGenerator
|
||||
|
||||
Ƭ **ActionPayloadGenerator**: *function*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
▸ (...`args`: any[]): *any*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`...args` | any[] |
|
||||
|
||||
___
|
||||
|
||||
### ActionsOf
|
||||
|
||||
Ƭ **ActionsOf**: *U extends Updux ? U["actions"] : object*
|
||||
|
||||
___
|
||||
|
||||
### CoduxesOf
|
||||
|
||||
Ƭ **CoduxesOf**: *U extends Updux<any, any, any, infer S> ? S : []*
|
||||
|
||||
___
|
||||
|
||||
### Dictionary
|
||||
|
||||
Ƭ **Dictionary**: *object*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
* \[ **key**: *string*\]: T
|
||||
|
||||
___
|
||||
|
||||
### Dux
|
||||
|
||||
Ƭ **Dux**: *object*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
* **actions**: *A*
|
||||
|
||||
* **coduxes**: *[Dux](globals.md#dux)[]*
|
||||
|
||||
* **initial**: *AggDuxState‹S, C›*
|
||||
|
||||
* **subduxes**: *[Dictionary](globals.md#dictionary)‹[Dux](globals.md#dux)›*
|
||||
|
||||
___
|
||||
|
||||
### DuxActions
|
||||
|
||||
Ƭ **DuxActions**:
|
||||
|
||||
___
|
||||
|
||||
### DuxActionsCoduxes
|
||||
|
||||
Ƭ **DuxActionsCoduxes**: *C extends Array<infer I> ? UnionToIntersection<ActionsOf<I>> : object*
|
||||
|
||||
___
|
||||
|
||||
### DuxActionsSubduxes
|
||||
|
||||
Ƭ **DuxActionsSubduxes**: *C extends object ? ActionsOf<C[keyof C]> : unknown*
|
||||
|
||||
___
|
||||
|
||||
### DuxSelectors
|
||||
|
||||
Ƭ **DuxSelectors**: *unknown extends X ? object : X*
|
||||
|
||||
___
|
||||
|
||||
### DuxState
|
||||
|
||||
Ƭ **DuxState**: *D extends object ? S : unknown*
|
||||
|
||||
___
|
||||
|
||||
### DuxStateCoduxes
|
||||
|
||||
Ƭ **DuxStateCoduxes**: *C extends Array<infer U> ? UnionToIntersection<StateOf<U>> : unknown*
|
||||
|
||||
___
|
||||
|
||||
### DuxStateGlobSub
|
||||
|
||||
Ƭ **DuxStateGlobSub**: *S extends object ? StateOf<I> : unknown*
|
||||
|
||||
___
|
||||
|
||||
### DuxStateSubduxes
|
||||
|
||||
Ƭ **DuxStateSubduxes**: *C extends object ? object : C extends object ? object : unknown*
|
||||
|
||||
___
|
||||
|
||||
### Effect
|
||||
|
||||
Ƭ **Effect**: *[string, [UpduxMiddleware](globals.md#upduxmiddleware) | [MwGen](globals.md#mwgen), undefined | false | true]*
|
||||
|
||||
___
|
||||
|
||||
### GenericActions
|
||||
|
||||
Ƭ **GenericActions**: *[Dictionary](globals.md#dictionary)‹ActionCreator‹string, function››*
|
||||
|
||||
___
|
||||
|
||||
### ItemsOf
|
||||
|
||||
Ƭ **ItemsOf**: *C extends object ? C[keyof C] : unknown*
|
||||
|
||||
___
|
||||
|
||||
### LocalDuxState
|
||||
|
||||
Ƭ **LocalDuxState**: *S extends never[] ? unknown[] : S*
|
||||
|
||||
___
|
||||
|
||||
### MaybePayload
|
||||
|
||||
Ƭ **MaybePayload**: *P extends object | string | boolean | number ? object : object*
|
||||
|
||||
___
|
||||
|
||||
### MaybeReturnType
|
||||
|
||||
Ƭ **MaybeReturnType**: *X extends function ? ReturnType<X> : unknown*
|
||||
|
||||
___
|
||||
|
||||
### Merge
|
||||
|
||||
Ƭ **Merge**: *[UnionToIntersection](globals.md#uniontointersection)‹T[keyof T]›*
|
||||
|
||||
___
|
||||
|
||||
### Mutation
|
||||
|
||||
Ƭ **Mutation**: *function*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
▸ (`payload`: A["payload"], `action`: A): *function*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`payload` | A["payload"] |
|
||||
`action` | A |
|
||||
|
||||
▸ (`state`: S): *S*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`state` | S |
|
||||
|
||||
___
|
||||
|
||||
### MutationEntry
|
||||
|
||||
Ƭ **MutationEntry**: *[ActionCreator | string, [Mutation](globals.md#mutation)‹any, [Action](globals.md#action)‹string, any››, undefined | false | true]*
|
||||
|
||||
___
|
||||
|
||||
### MwGen
|
||||
|
||||
Ƭ **MwGen**: *function*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
▸ (): *[UpduxMiddleware](globals.md#upduxmiddleware)*
|
||||
|
||||
___
|
||||
|
||||
### Next
|
||||
|
||||
Ƭ **Next**: *function*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
▸ (`action`: [Action](globals.md#action)): *any*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`action` | [Action](globals.md#action) |
|
||||
|
||||
___
|
||||
|
||||
### RebaseSelector
|
||||
|
||||
Ƭ **RebaseSelector**: *object*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
___
|
||||
|
||||
### Selector
|
||||
|
||||
Ƭ **Selector**: *function*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
▸ (`state`: S): *unknown*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`state` | S |
|
||||
|
||||
___
|
||||
|
||||
### SelectorsOf
|
||||
|
||||
Ƭ **SelectorsOf**: *C extends object ? S : unknown*
|
||||
|
||||
___
|
||||
|
||||
### StateOf
|
||||
|
||||
Ƭ **StateOf**: *D extends object ? I : unknown*
|
||||
|
||||
___
|
||||
|
||||
### StoreWithDispatchActions
|
||||
|
||||
Ƭ **StoreWithDispatchActions**: *Store‹S› & object*
|
||||
|
||||
___
|
||||
|
||||
### SubMutations
|
||||
|
||||
Ƭ **SubMutations**: *object*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
* \[ **slice**: *string*\]: [Dictionary](globals.md#dictionary)‹[Mutation](globals.md#mutation)›
|
||||
|
||||
___
|
||||
|
||||
### Submws
|
||||
|
||||
Ƭ **Submws**: *[Dictionary](globals.md#dictionary)‹[UpduxMiddleware](globals.md#upduxmiddleware)›*
|
||||
|
||||
___
|
||||
|
||||
### UnionToIntersection
|
||||
|
||||
Ƭ **UnionToIntersection**: *U extends any ? function : never extends function ? I : never*
|
||||
|
||||
___
|
||||
|
||||
### UpduxActions
|
||||
|
||||
Ƭ **UpduxActions**: *U extends Updux ? UnionToIntersection<UpduxLocalActions<U> | ActionsOf<CoduxesOf<U>[keyof CoduxesOf<U>]>> : object*
|
||||
|
||||
___
|
||||
|
||||
### UpduxConfig
|
||||
|
||||
Ƭ **UpduxConfig**: *Partial‹object›*
|
||||
|
||||
Configuration object given to Updux's constructor.
|
||||
|
||||
#### arguments
|
||||
|
||||
##### initial
|
||||
|
||||
Default initial state of the reducer. If applicable, is merged with
|
||||
the subduxes initial states, with the parent having precedence.
|
||||
|
||||
If not provided, defaults to an empty object.
|
||||
|
||||
##### actions
|
||||
|
||||
[Actions](/concepts/Actions) used by the updux.
|
||||
|
||||
```js
|
||||
import { dux } from 'updux';
|
||||
import { action, payload } from 'ts-action';
|
||||
|
||||
const bar = action('BAR', payload<int>());
|
||||
const foo = action('FOO');
|
||||
|
||||
const myDux = dux({
|
||||
actions: {
|
||||
bar
|
||||
},
|
||||
mutations: [
|
||||
[ foo, () => state => state ]
|
||||
]
|
||||
});
|
||||
|
||||
myDux.actions.foo({ x: 1, y: 2 }); // => { type: foo, x:1, y:2 }
|
||||
myDux.actions.bar(2); // => { type: bar, payload: 2 }
|
||||
```
|
||||
|
||||
New actions used directly in mutations and effects will be added to the
|
||||
dux actions -- that is, they will be accessible via `dux.actions` -- but will
|
||||
not appear as part of its Typescript type.
|
||||
|
||||
##### selectors
|
||||
|
||||
Dictionary of selectors for the current updux. The updux also
|
||||
inherit its subduxes' selectors.
|
||||
|
||||
The selectors are available via the class' getter.
|
||||
|
||||
##### mutations
|
||||
|
||||
mutations: [
|
||||
[ action, mutation, isSink ],
|
||||
...
|
||||
]
|
||||
|
||||
or
|
||||
|
||||
mutations: {
|
||||
action: mutation,
|
||||
...
|
||||
}
|
||||
|
||||
List of mutations for assign to the dux. If you want Typescript goodness, you
|
||||
probably want to use `addMutation()` instead.
|
||||
|
||||
In its generic array-of-array form,
|
||||
each mutation tuple contains: the action, the mutation,
|
||||
and boolean indicating if this is a sink mutation.
|
||||
|
||||
The action can be an action creator function or a string. If it's a string, it's considered to be the
|
||||
action type and a generic `action( actionName, payload() )` creator will be
|
||||
generated for it. If an action is not already defined in the `actions`
|
||||
parameter, it'll be automatically added.
|
||||
|
||||
The pseudo-action type `*` can be used to match any action not explicitly matched by other mutations.
|
||||
|
||||
```js
|
||||
const todosUpdux = updux({
|
||||
mutations: {
|
||||
add: todo => state => [ ...state, todo ],
|
||||
done: done_id => u.map( u.if( ({id} => id === done_id), {done: true} ) ),
|
||||
'*' (payload,action) => state => {
|
||||
console.warn( "unexpected action ", action.type );
|
||||
return state;
|
||||
},
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
The signature of the mutations is `(payload,action) => state => newState`.
|
||||
It is designed to play well with `Updeep` (and [Immer](https://immerjs.github.io/immer/docs/introduction)). This way, instead of doing
|
||||
|
||||
```js
|
||||
mutation: {
|
||||
renameTodo: newName => state => { ...state, name: newName }
|
||||
}
|
||||
```
|
||||
|
||||
we can do
|
||||
|
||||
```js
|
||||
mutation: {
|
||||
renameTodo: newName => u({ name: newName })
|
||||
}
|
||||
```
|
||||
|
||||
The final argument is the optional boolean `isSink`. If it is true, it'll
|
||||
prevent subduxes' mutations on the same action. It defaults to `false`.
|
||||
|
||||
The object version of the argument can be used as a shortcut when all actions
|
||||
are strings. In that case, `isSink` is `false` for all mutations.
|
||||
|
||||
##### groomMutations
|
||||
|
||||
Function that can be provided to alter all local mutations of the updux
|
||||
(the mutations of subduxes are left untouched).
|
||||
|
||||
Can be used, for example, for Immer integration:
|
||||
|
||||
```js
|
||||
import Updux from 'updux';
|
||||
import { produce } from 'Immer';
|
||||
|
||||
const updux = new Updux({
|
||||
initial: { counter: 0 },
|
||||
groomMutations: mutation => (...args) => produce( mutation(...args) ),
|
||||
mutations: {
|
||||
add: (inc=1) => draft => draft.counter += inc
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Or perhaps for debugging:
|
||||
|
||||
```js
|
||||
import Updux from 'updux';
|
||||
|
||||
const updux = new Updux({
|
||||
initial: { counter: 0 },
|
||||
groomMutations: mutation => (...args) => state => {
|
||||
console.log( "got action ", args[1] );
|
||||
return mutation(...args)(state);
|
||||
}
|
||||
});
|
||||
```
|
||||
##### subduxes
|
||||
|
||||
Object mapping slices of the state to sub-upduxes. In addition to creating
|
||||
sub-reducers for those slices, it'll make the parend updux inherit all the
|
||||
actions and middleware from its subduxes.
|
||||
|
||||
For example, if in plain Redux you would do
|
||||
|
||||
```js
|
||||
import { combineReducers } from 'redux';
|
||||
import todosReducer from './todos';
|
||||
import statisticsReducer from './statistics';
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
todos: todosReducer,
|
||||
stats: statisticsReducer,
|
||||
});
|
||||
```
|
||||
|
||||
then with Updux you'd do
|
||||
|
||||
```js
|
||||
import { updux } from 'updux';
|
||||
import todos from './todos';
|
||||
import statistics from './statistics';
|
||||
|
||||
const rootUpdux = updux({
|
||||
subduxes: {
|
||||
todos,
|
||||
statistics
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
##### effects
|
||||
|
||||
Array of arrays or plain object defining asynchronous actions and side-effects triggered by actions.
|
||||
The effects themselves are Redux middleware, with the `dispatch`
|
||||
property of the first argument augmented with all the available actions.
|
||||
|
||||
```
|
||||
updux({
|
||||
effects: {
|
||||
fetch: ({dispatch}) => next => async (action) => {
|
||||
next(action);
|
||||
|
||||
let result = await fetch(action.payload.url).then( result => result.json() );
|
||||
dispatch.fetchSuccess(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
**`example`**
|
||||
|
||||
```
|
||||
import Updux from 'updux';
|
||||
import { actions, payload } from 'ts-action';
|
||||
import u from 'updeep';
|
||||
|
||||
const todoUpdux = new Updux({
|
||||
initial: {
|
||||
done: false,
|
||||
note: "",
|
||||
},
|
||||
actions: {
|
||||
finish: action('FINISH', payload()),
|
||||
edit: action('EDIT', payload()),
|
||||
},
|
||||
mutations: [
|
||||
[ edit, note => u({note}) ]
|
||||
],
|
||||
selectors: {
|
||||
getNote: state => state.note
|
||||
},
|
||||
groomMutations: mutation => transform(mutation),
|
||||
subduxes: {
|
||||
foo
|
||||
},
|
||||
effects: {
|
||||
finish: () => next => action => {
|
||||
console.log( "Woo! one more bites the dust" );
|
||||
}
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
___
|
||||
|
||||
### UpduxLocalActions
|
||||
|
||||
Ƭ **UpduxLocalActions**: *S extends Updux<any, null> ? object : S extends Updux<any, infer A> ? A : object*
|
||||
|
||||
___
|
||||
|
||||
### UpduxMiddleware
|
||||
|
||||
Ƭ **UpduxMiddleware**: *function*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
▸ (`api`: UpduxMiddlewareAPI‹S, X›): *function*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`api` | UpduxMiddlewareAPI‹S, X› |
|
||||
|
||||
▸ (`next`: Function): *function*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`next` | Function |
|
||||
|
||||
▸ (`action`: A): *any*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`action` | A |
|
||||
|
||||
___
|
||||
|
||||
### Upreducer
|
||||
|
||||
Ƭ **Upreducer**: *function*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
▸ (`action`: [Action](globals.md#action)): *function*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`action` | [Action](globals.md#action) |
|
||||
|
||||
▸ (`state`: S): *S*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`state` | S |
|
||||
|
||||
## Variables
|
||||
|
||||
### `Const` subEffects
|
||||
|
||||
• **subEffects**: *[Effect](globals.md#effect)* = [ '*', subMiddleware ] as any
|
||||
|
||||
___
|
||||
|
||||
### `Const` updux
|
||||
|
||||
• **updux**: *[Updux](classes/updux.md)‹unknown, null, unknown, object›* = new Updux({
|
||||
subduxes: {
|
||||
foo: dux({ initial: "banana" })
|
||||
}
|
||||
})
|
||||
|
||||
## Functions
|
||||
|
||||
### `Const` MiddlewareFor
|
||||
|
||||
▸ **MiddlewareFor**(`type`: any, `mw`: Middleware): *Middleware*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`type` | any |
|
||||
`mw` | Middleware |
|
||||
|
||||
**Returns:** *Middleware*
|
||||
|
||||
___
|
||||
|
||||
### buildActions
|
||||
|
||||
▸ **buildActions**(`actions`: [ActionPair](globals.md#actionpair)[]): *[Dictionary](globals.md#dictionary)‹ActionCreator‹string, function››*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type | Default |
|
||||
------ | ------ | ------ |
|
||||
`actions` | [ActionPair](globals.md#actionpair)[] | [] |
|
||||
|
||||
**Returns:** *[Dictionary](globals.md#dictionary)‹ActionCreator‹string, function››*
|
||||
|
||||
___
|
||||
|
||||
### buildCreateStore
|
||||
|
||||
▸ **buildCreateStore**<**S**, **A**>(`reducer`: Reducer‹S›, `middleware`: Middleware, `actions`: A): *function*
|
||||
|
||||
**Type parameters:**
|
||||
|
||||
▪ **S**
|
||||
|
||||
▪ **A**
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type | Default |
|
||||
------ | ------ | ------ |
|
||||
`reducer` | Reducer‹S› | - |
|
||||
`middleware` | Middleware | - |
|
||||
`actions` | A | {} as A |
|
||||
|
||||
**Returns:** *function*
|
||||
|
||||
▸ (`initial?`: S, `injectEnhancer?`: Function): *Store‹S› & object*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`initial?` | S |
|
||||
`injectEnhancer?` | Function |
|
||||
|
||||
___
|
||||
|
||||
### buildInitial
|
||||
|
||||
▸ **buildInitial**(`initial`: any, `coduxes`: any, `subduxes`: any): *any*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type | Default |
|
||||
------ | ------ | ------ |
|
||||
`initial` | any | - |
|
||||
`coduxes` | any | [] |
|
||||
`subduxes` | any | {} |
|
||||
|
||||
**Returns:** *any*
|
||||
|
||||
___
|
||||
|
||||
### buildMiddleware
|
||||
|
||||
▸ **buildMiddleware**<**S**>(`local`: [UpduxMiddleware](globals.md#upduxmiddleware)[], `co`: [UpduxMiddleware](globals.md#upduxmiddleware)[], `sub`: [Submws](globals.md#submws)): *[UpduxMiddleware](globals.md#upduxmiddleware)‹S›*
|
||||
|
||||
**Type parameters:**
|
||||
|
||||
▪ **S**
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type | Default |
|
||||
------ | ------ | ------ |
|
||||
`local` | [UpduxMiddleware](globals.md#upduxmiddleware)[] | [] |
|
||||
`co` | [UpduxMiddleware](globals.md#upduxmiddleware)[] | [] |
|
||||
`sub` | [Submws](globals.md#submws) | {} |
|
||||
|
||||
**Returns:** *[UpduxMiddleware](globals.md#upduxmiddleware)‹S›*
|
||||
|
||||
___
|
||||
|
||||
### buildMutations
|
||||
|
||||
▸ **buildMutations**(`mutations`: [Dictionary](globals.md#dictionary)‹[Mutation](globals.md#mutation) | [[Mutation](globals.md#mutation), boolean | undefined]›, `subduxes`: object, `coduxes`: [Upreducer](globals.md#upreducer)[]): *object*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type | Default |
|
||||
------ | ------ | ------ |
|
||||
`mutations` | [Dictionary](globals.md#dictionary)‹[Mutation](globals.md#mutation) | [[Mutation](globals.md#mutation), boolean | undefined]› | {} |
|
||||
`subduxes` | object | {} |
|
||||
`coduxes` | [Upreducer](globals.md#upreducer)[] | [] |
|
||||
|
||||
**Returns:** *object*
|
||||
|
||||
___
|
||||
|
||||
### buildSelectors
|
||||
|
||||
▸ **buildSelectors**(`localSelectors`: [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)›, `coduxes`: [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)›[], `subduxes`: [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)›): *object*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type | Default |
|
||||
------ | ------ | ------ |
|
||||
`localSelectors` | [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)› | {} |
|
||||
`coduxes` | [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)›[] | [] |
|
||||
`subduxes` | [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)› | {} |
|
||||
|
||||
**Returns:** *object*
|
||||
|
||||
___
|
||||
|
||||
### buildUpreducer
|
||||
|
||||
▸ **buildUpreducer**<**S**>(`initial`: S, `mutations`: [Dictionary](globals.md#dictionary)‹[Mutation](globals.md#mutation)‹S››): *[Upreducer](globals.md#upreducer)‹S›*
|
||||
|
||||
**Type parameters:**
|
||||
|
||||
▪ **S**
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`initial` | S |
|
||||
`mutations` | [Dictionary](globals.md#dictionary)‹[Mutation](globals.md#mutation)‹S›› |
|
||||
|
||||
**Returns:** *[Upreducer](globals.md#upreducer)‹S›*
|
||||
|
||||
___
|
||||
|
||||
### `Const` coduxes
|
||||
|
||||
▸ **coduxes**<**C**, **U**>(...`coduxes`: U): *object*
|
||||
|
||||
**Type parameters:**
|
||||
|
||||
▪ **C**: *[Dux](globals.md#dux)*
|
||||
|
||||
▪ **U**: *[C]*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`...coduxes` | U |
|
||||
|
||||
**Returns:** *object*
|
||||
|
||||
* **coduxes**: *U*
|
||||
|
||||
___
|
||||
|
||||
### `Const` composeMutations
|
||||
|
||||
▸ **composeMutations**(`mutations`: [Mutation](globals.md#mutation)[]): *function | (Anonymous function)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`mutations` | [Mutation](globals.md#mutation)[] |
|
||||
|
||||
**Returns:** *function | (Anonymous function)*
|
||||
|
||||
___
|
||||
|
||||
### `Const` composeMw
|
||||
|
||||
▸ **composeMw**(`mws`: [UpduxMiddleware](globals.md#upduxmiddleware)[]): *(Anonymous function)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`mws` | [UpduxMiddleware](globals.md#upduxmiddleware)[] |
|
||||
|
||||
**Returns:** *(Anonymous function)*
|
||||
|
||||
___
|
||||
|
||||
### `Const` dux
|
||||
|
||||
▸ **dux**<**S**, **A**, **X**, **C**>(`config`: C): *object*
|
||||
|
||||
**Type parameters:**
|
||||
|
||||
▪ **S**
|
||||
|
||||
▪ **A**
|
||||
|
||||
▪ **X**
|
||||
|
||||
▪ **C**: *[UpduxConfig](globals.md#upduxconfig)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`config` | C |
|
||||
|
||||
**Returns:** *object*
|
||||
|
||||
* **actions**: = this.actions
|
||||
|
||||
* **coduxes**: *object[]* = this.coduxes
|
||||
|
||||
* **createStore**(): *function*
|
||||
|
||||
* (`initial?`: S, `injectEnhancer?`: Function): *Store‹S› & object*
|
||||
|
||||
* **initial**: = this.initial
|
||||
|
||||
* **middleware**(): *function*
|
||||
|
||||
* (`api`: UpduxMiddlewareAPI‹S, X›): *function*
|
||||
|
||||
* (`next`: Function): *function*
|
||||
|
||||
* (`action`: A): *any*
|
||||
|
||||
* **mutations**(): *object*
|
||||
|
||||
* **reducer**(): *function*
|
||||
|
||||
* (`state`: S | undefined, `action`: [Action](globals.md#action)): *S*
|
||||
|
||||
* **selectors**: = this.selectors
|
||||
|
||||
* **subduxes**(): *object*
|
||||
|
||||
* **upreducer**(): *function*
|
||||
|
||||
* (`action`: [Action](globals.md#action)): *function*
|
||||
|
||||
* (`state`: S): *S*
|
||||
|
||||
___
|
||||
|
||||
### `Const` effectToMw
|
||||
|
||||
▸ **effectToMw**(`effect`: [Effect](globals.md#effect), `actions`: [Dictionary](globals.md#dictionary)‹ActionCreator›, `selectors`: [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)›): *subMiddleware | augmented*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`effect` | [Effect](globals.md#effect) |
|
||||
`actions` | [Dictionary](globals.md#dictionary)‹ActionCreator› |
|
||||
`selectors` | [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)› |
|
||||
|
||||
**Returns:** *subMiddleware | augmented*
|
||||
|
||||
___
|
||||
|
||||
### sliceMw
|
||||
|
||||
▸ **sliceMw**(`slice`: string, `mw`: [UpduxMiddleware](globals.md#upduxmiddleware)): *[UpduxMiddleware](globals.md#upduxmiddleware)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`slice` | string |
|
||||
`mw` | [UpduxMiddleware](globals.md#upduxmiddleware) |
|
||||
|
||||
**Returns:** *[UpduxMiddleware](globals.md#upduxmiddleware)*
|
||||
|
||||
___
|
||||
|
||||
### `Const` subMiddleware
|
||||
|
||||
▸ **subMiddleware**(): *(Anonymous function)*
|
||||
|
||||
**Returns:** *(Anonymous function)*
|
||||
|
||||
___
|
||||
|
||||
### subSelectors
|
||||
|
||||
▸ **subSelectors**(`__namedParameters`: [string, Function]): *[string, [Selector](globals.md#selector)][]*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`__namedParameters` | [string, Function] |
|
||||
|
||||
**Returns:** *[string, [Selector](globals.md#selector)][]*
|
215
docs/README.md
|
@ -1,101 +1,105 @@
|
|||
|
||||
# What's Updux?
|
||||
|
||||
So, I'm a fan of [Redux](https://redux.js.org).
|
||||
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.
|
||||
|
||||
As I was looking into tools to help cut on its boilerplate,
|
||||
I came across [rematch](https://rematch.github.io/rematch).
|
||||
It has some pretty darn good ideas.
|
||||
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
|
||||
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.
|
||||
|
||||
Hence: `Updux`. Heavily inspired by `rematch`, but twisted
|
||||
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 all things pertaining to a store are defined
|
||||
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.
|
||||
* Mutations auto-unwrapping the payload of actions for you.
|
||||
* TypeScript types.
|
||||
* Leverage [ts-action](https://www.npmjs.com/package/ts-action) for action
|
||||
creation.
|
||||
- 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, likely to go through
|
||||
big changes before I find the perfect balance between ease of use and sanity.
|
||||
Caveat Emptor.
|
||||
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 { action, payload } from 'ts-action';
|
||||
import updux from 'updux';
|
||||
|
||||
import otherDux from './otherUpdux';
|
||||
import otherUpdux from './otherUpdux';
|
||||
|
||||
const inc = action( 'INC', payload<int>() );
|
||||
|
||||
const updux = new Updux({
|
||||
const {
|
||||
initial,
|
||||
reducer,
|
||||
actions,
|
||||
middleware,
|
||||
createStore,
|
||||
} = new Updux({
|
||||
initial: {
|
||||
counter: 0,
|
||||
},
|
||||
actions: {
|
||||
inc
|
||||
},
|
||||
subduxes: {
|
||||
otherDux,
|
||||
}
|
||||
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 }
|
||||
}),
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
updux.addMutation( inc, increment => u({counter: s => s + increment }));
|
||||
const store = createStore();
|
||||
|
||||
updux.addEffect( '*', api => next => action => {
|
||||
console.log( "hey, look, an action zoomed by!", action );
|
||||
next(action);
|
||||
} );
|
||||
|
||||
const myDux = updux.asDux;
|
||||
|
||||
const store = myDux.createStore();
|
||||
|
||||
store.dispatch( myDux.actions.inc(3) );
|
||||
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
|
||||
|
||||
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 "compiled" (as in, no more editable and with all its properties resolved) output of the Updux instance via its `asDux()` getter:
|
||||
recommend that you export the Updux instance as the default export:
|
||||
|
||||
```
|
||||
import Updux from 'updux';
|
||||
|
||||
const updux = new Updux({ ... });
|
||||
|
||||
export default updux.asDux;
|
||||
export default updux;
|
||||
```
|
||||
|
||||
Then you can use them as subduxes like this:
|
||||
|
||||
```
|
||||
import Updux from 'updux';
|
||||
import foo from './foo'; // foo is a dux
|
||||
import bar from './bar'; // bar is a dux as well
|
||||
import foo from './foo'; // foo is an Updux
|
||||
import bar from './bar'; // bar is an Updux as well
|
||||
|
||||
const updux = new Updux({
|
||||
subduxes: {
|
||||
|
@ -103,3 +107,120 @@ const updux = new Updux({
|
|||
}
|
||||
});
|
||||
```
|
||||
|
||||
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
|
||||
}
|
||||
});
|
||||
|
||||
```
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
- [README](/README.md)
|
||||
- [Tutorial](/tutorial.md)
|
||||
- [Concepts](/concepts.md)
|
||||
- [Recipes](/recipes.md)
|
||||
- API
|
||||
- [Top-level exports](/exports.md)
|
||||
- [main index](/API/globals.md)
|
||||
* [Home](/)
|
||||
* [ Tutorial ](tutorial.md)
|
||||
* [ Recipes ](recipes.md)
|
||||
|
|
Before Width: | Height: | Size: 9.4 KiB |
Before Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 480 B |
Before Width: | Height: | Size: 855 B |
|
@ -1,812 +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#subduxupreducer" class="tsd-kind-icon">subdux<wbr>Upreducer</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 <a href="https://github.com/yanick/updux/blob/8d4542f/src/updux.ts#L109">updux.ts:109</a></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 <a href="https://github.com/yanick/updux/blob/8d4542f/src/updux.ts#L99">updux.ts:99</a></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 <a href="https://github.com/yanick/updux/blob/8d4542f/src/updux.ts#L62">updux.ts:62</a></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 <a href="https://github.com/yanick/updux/blob/8d4542f/src/updux.ts#L53">updux.ts:53</a></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 <a href="https://github.com/yanick/updux/blob/8d4542f/src/updux.ts#L162">updux.ts:162</a></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 <a href="https://github.com/yanick/updux/blob/8d4542f/src/updux.ts#L258">updux.ts:258</a></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 <a href="https://github.com/yanick/updux/blob/8d4542f/src/updux.ts#L241">updux.ts:241</a></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><a href="../globals.html#upduxmiddleware" class="tsd-signature-type">UpduxMiddleware</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 <a href="https://github.com/yanick/updux/blob/8d4542f/src/updux.ts#L140">updux.ts:140</a></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.
|
||||
Note that <code>getState</code> will always return the state of the
|
||||
local updux. The function <code>getRootState</code> is provided
|
||||
alongside <code>getState</code> to get the root state.</p>
|
||||
</div>
|
||||
</div>
|
||||
<h4 class="tsd-returns-title">Returns <a href="../globals.html#upduxmiddleware" class="tsd-signature-type">UpduxMiddleware</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="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 <a href="https://github.com/yanick/updux/blob/8d4542f/src/updux.ts#L191">updux.ts:191</a></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 <a href="https://github.com/yanick/updux/blob/8d4542f/src/updux.ts#L182">updux.ts:182</a></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="subduxupreducer" class="tsd-anchor"></a>
|
||||
<h3>subdux<wbr>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> subduxUpreducer<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 <a href="https://github.com/yanick/updux/blob/8d4542f/src/updux.ts#L212">updux.ts:212</a></li>
|
||||
</ul>
|
||||
</aside>
|
||||
<div class="tsd-comment tsd-typography">
|
||||
<div class="lead">
|
||||
<p>Returns the upreducer made of the merge of all sudbuxes reducers, without
|
||||
the local mutations. Useful, for example, for sink mutations.</p>
|
||||
</div>
|
||||
<dl class="tsd-comment-tags">
|
||||
<dt>example</dt>
|
||||
<dd><pre><code><span class="hljs-keyword">import</span> todo <span class="hljs-keyword">from</span> <span class="hljs-string">'./todo'</span>; <span class="hljs-comment">// updux for a single todo</span>
|
||||
<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> u <span class="hljs-keyword">from</span> <span class="hljs-string">'updeep'</span>;
|
||||
|
||||
<span class="hljs-keyword">const</span> todos = <span class="hljs-keyword">new</span> Updux({ initial: [], subduxes: { <span class="hljs-string">'*'</span>: todo } });
|
||||
todos.addMutation(
|
||||
todo.actions.done,
|
||||
<span class="hljs-function">(<span class="hljs-params">{todo_id},action</span>) =></span> u.map( u.if( u.is(<span class="hljs-string">'id'</span>,todo_id) ), todos.subduxUpreducer(action) )
|
||||
<span class="hljs-literal">true</span>
|
||||
);</code></pre></dd>
|
||||
</dl>
|
||||
</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>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">function</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-descriptions">
|
||||
<li class="tsd-description">
|
||||
<h4 class="tsd-parameters-title">Parameters</h4>
|
||||
<ul class="tsd-parameters">
|
||||
<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">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-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></h5>
|
||||
</li>
|
||||
</ul>
|
||||
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">S</span></h4>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</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 <a href="https://github.com/yanick/updux/blob/8d4542f/src/updux.ts#L174">updux.ts:174</a></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>, isSink<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">undefined</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">false</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">true</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 <a href="https://github.com/yanick/updux/blob/8d4542f/src/updux.ts#L283">updux.ts:283</a></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>
|
||||
<li>
|
||||
<h5><span class="tsd-flag ts-flagOptional">Optional</span> isSink: <span class="tsd-signature-type">undefined</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">false</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">true</span></h5>
|
||||
<div class="tsd-comment tsd-typography">
|
||||
<p>If <code>true</code>, disables the subduxes mutations for this action. To
|
||||
conditionally run the subduxes mutations, check out <a href="updux.html#subduxupreducer">subduxUpreducer</a>.</p>
|
||||
</div>
|
||||
</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#subduxupreducer" class="tsd-kind-icon">subdux<wbr>Upreducer</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-interface tsd-has-type-parameter">
|
||||
<a href="../interfaces/upduxmiddlewareapi.html" class="tsd-kind-icon">Updux<wbr>MiddlewareAPI</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#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#upduxmiddleware" class="tsd-kind-icon">Updux<wbr>Middleware</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#slicemw" class="tsd-kind-icon">slice<wbr>Mw</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>
|
|
@ -1,28 +0,0 @@
|
|||
# Updux concepts
|
||||
|
||||
## actions
|
||||
|
||||
Updux internally uses the package `ts-action` to create action creator
|
||||
functions. Even if you don't use Typescript, I recommend that you use it,
|
||||
as it does what it does very well. But if you don't want to, no big deal.
|
||||
Updux will recognize a function as an action creator if it has a `type`
|
||||
property. So a homegrown creator could be as simple as:
|
||||
|
||||
```js
|
||||
function action(type) {
|
||||
return Object.assign( payload => ({type, payload}), { type } )
|
||||
}
|
||||
```
|
||||
|
||||
## effects
|
||||
|
||||
Updux effects are redux middlewares. I kept that format, and the
|
||||
use of `next` mostly because I wanted to give myself a way to alter
|
||||
actions before they hit the reducer, something that `redux-saga` and
|
||||
`rematch` don't allow.
|
||||
|
||||
An effect has the signature
|
||||
|
||||
```js
|
||||
const effect = ({ getState, dispatch }) => next => action => { ... }
|
||||
```
|
|
@ -1,12 +0,0 @@
|
|||
# Top-level exports
|
||||
|
||||
## Default export
|
||||
|
||||
* [Updux](/API/classes/updux)
|
||||
|
||||
## Exports
|
||||
|
||||
* [Updux](/API/classes/updux)
|
||||
* [dux](/API/globals?id=const-dux)
|
||||
* [coduxes](/API/globals?id=const-coduxes)
|
||||
* [subEffects](/API/globals?id=const-subeffects)
|
1306
docs/globals.html
|
@ -1,24 +1,24 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>updux - Updeep-friendly Redux helper framework</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<meta name="description" content="Updeep-friendly Redux helper framework">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<link rel="stylesheet" href="//unpkg.com/docsify/lib/themes/vue.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script>
|
||||
window.$docsify = {
|
||||
name: 'updux',
|
||||
repo: 'https://github.com/yanick/updux',
|
||||
loadSidebar: true,
|
||||
subMaxLevel: 4,
|
||||
relativePath: true,
|
||||
}
|
||||
</script>
|
||||
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<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>
|
||||
<div id="app"></div>
|
||||
<script>
|
||||
window.$docsify = {
|
||||
loadSidebar: true,
|
||||
name: 'updux',
|
||||
repo: '',
|
||||
subMaxLevel: 3,
|
||||
}
|
||||
</script>
|
||||
<!-- Docsify v4 -->
|
||||
<script src="docsify.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,337 +0,0 @@
|
|||
<!doctype html>
|
||||
<html class="default no-js">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>UpduxMiddlewareAPI | 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="upduxmiddlewareapi.html">UpduxMiddlewareAPI</a>
|
||||
</li>
|
||||
</ul>
|
||||
<h1>Interface UpduxMiddlewareAPI<S></h1>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div class="container container-main">
|
||||
<div class="row">
|
||||
<div class="col-8 col-content">
|
||||
<section class="tsd-panel tsd-type-parameters">
|
||||
<h3>Type parameters</h3>
|
||||
<ul class="tsd-type-parameters">
|
||||
<li>
|
||||
<h4>S</h4>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="tsd-panel tsd-hierarchy">
|
||||
<h3>Hierarchy</h3>
|
||||
<ul class="tsd-hierarchy">
|
||||
<li>
|
||||
<span class="target">UpduxMiddlewareAPI</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>Properties</h3>
|
||||
<ul class="tsd-index-list">
|
||||
<li class="tsd-kind-property tsd-parent-kind-interface"><a href="upduxmiddlewareapi.html#dispatch" class="tsd-kind-icon">dispatch</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-interface"><a href="upduxmiddlewareapi.html#getrootstate" class="tsd-kind-icon">get<wbr>Root<wbr>State</a></li>
|
||||
<li class="tsd-kind-method tsd-parent-kind-interface"><a href="upduxmiddlewareapi.html#getstate" class="tsd-kind-icon">get<wbr>State</a></li>
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
</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-interface">
|
||||
<a name="dispatch" class="tsd-anchor"></a>
|
||||
<h3>dispatch</h3>
|
||||
<div class="tsd-signature tsd-kind-icon">dispatch<span class="tsd-signature-symbol">:</span> <a href="../globals.html#upduxdispatch" class="tsd-signature-type">UpduxDispatch</a></div>
|
||||
<aside class="tsd-sources">
|
||||
<ul>
|
||||
<li>Defined in <a href="https://github.com/yanick/updux/blob/8d4542f/src/types.ts#L187">types.ts:187</a></li>
|
||||
</ul>
|
||||
</aside>
|
||||
</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-interface">
|
||||
<a name="getrootstate" class="tsd-anchor"></a>
|
||||
<h3>get<wbr>Root<wbr>State</h3>
|
||||
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface">
|
||||
<li class="tsd-signature tsd-kind-icon">get<wbr>Root<wbr>State<span class="tsd-signature-symbol">(</span><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">
|
||||
<aside class="tsd-sources">
|
||||
<ul>
|
||||
<li>Defined in <a href="https://github.com/yanick/updux/blob/8d4542f/src/types.ts#L189">types.ts:189</a></li>
|
||||
</ul>
|
||||
</aside>
|
||||
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">S</span></h4>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface">
|
||||
<a name="getstate" class="tsd-anchor"></a>
|
||||
<h3>get<wbr>State</h3>
|
||||
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface">
|
||||
<li class="tsd-signature tsd-kind-icon">get<wbr>State<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span></li>
|
||||
</ul>
|
||||
<ul class="tsd-descriptions">
|
||||
<li class="tsd-description">
|
||||
<aside class="tsd-sources">
|
||||
<ul>
|
||||
<li>Defined in <a href="https://github.com/yanick/updux/blob/8d4542f/src/types.ts#L188">types.ts:188</a></li>
|
||||
</ul>
|
||||
</aside>
|
||||
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">any</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">
|
||||
<li class=" tsd-kind-class tsd-has-type-parameter">
|
||||
<a href="../classes/updux.html" class="tsd-kind-icon">Updux</a>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="current">
|
||||
<li class="current tsd-kind-interface tsd-has-type-parameter">
|
||||
<a href="upduxmiddlewareapi.html" class="tsd-kind-icon">Updux<wbr>MiddlewareAPI</a>
|
||||
<ul>
|
||||
<li class=" tsd-kind-property tsd-parent-kind-interface">
|
||||
<a href="upduxmiddlewareapi.html#dispatch" class="tsd-kind-icon">dispatch</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-method tsd-parent-kind-interface">
|
||||
<a href="upduxmiddlewareapi.html#getrootstate" class="tsd-kind-icon">get<wbr>Root<wbr>State</a>
|
||||
</li>
|
||||
<li class=" tsd-kind-method tsd-parent-kind-interface">
|
||||
<a href="upduxmiddlewareapi.html#getstate" class="tsd-kind-icon">get<wbr>State</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#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#upduxmiddleware" class="tsd-kind-icon">Updux<wbr>Middleware</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#slicemw" class="tsd-kind-icon">slice<wbr>Mw</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>
|
|
@ -2,53 +2,42 @@
|
|||
|
||||
## 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 map away all items to the sub-reducer:
|
||||
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: {
|
||||
review: action('REVIEW'),
|
||||
done: action('DONE',payload<int>()),
|
||||
done: null,
|
||||
doneAll: null,
|
||||
},
|
||||
mutations: {
|
||||
review: () => u({reviewed: true}),
|
||||
done: () => u({done: true}),
|
||||
done,
|
||||
doneAll: done,
|
||||
},
|
||||
});
|
||||
|
||||
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 can be
|
||||
rewritten as:
|
||||
|
||||
```
|
||||
const todos = new Updux({
|
||||
initial: [],
|
||||
subduxes: { '*': todo },
|
||||
actions: { addTodo: null },
|
||||
mutations: {
|
||||
addTodo: text => state => [ ...state, { text } ]
|
||||
}
|
||||
});
|
||||
|
||||
todos.addMutation(
|
||||
todo.actions.done,
|
||||
(id,action) => u.map(u.if(u.is('id',id), todo.upreducer(action))),
|
||||
true
|
||||
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
|
||||
);
|
||||
```
|
||||
|
||||
The advantages being that the actions/mutations/effects of the subdux will be
|
||||
imported by the root updux as usual, and all actions not
|
||||
overridden by a sink mutation will trickle down automatically.
|
||||
```
|
||||
|
||||
## Usage with Immer
|
||||
|
||||
|
@ -63,7 +52,7 @@ import Updux from 'updux';
|
|||
const updux = new Updux({
|
||||
initial: { counter: 0 },
|
||||
mutations: {
|
||||
add: (inc=1) => state => { counter: counter + inc }
|
||||
add: (inc=1) => state => ({ counter: state.counter + inc })
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -74,7 +63,7 @@ Converting it to Immer would look like:
|
|||
|
||||
```
|
||||
import Updux from 'updux';
|
||||
import { produce } from 'Immer';
|
||||
import { produce } from 'immer';
|
||||
|
||||
const updux = new Updux({
|
||||
initial: { counter: 0 },
|
||||
|
@ -91,7 +80,7 @@ can be used to wrap all mutations with it:
|
|||
|
||||
```
|
||||
import Updux from 'updux';
|
||||
import { produce } from 'Immer';
|
||||
import { produce } from 'immer';
|
||||
|
||||
const updux = new Updux({
|
||||
initial: { counter: 0 },
|
||||
|
|
|
@ -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' ]);
|
||||
} )
|
|
@ -0,0 +1,40 @@
|
|||
import { test, expect } from 'vitest';
|
||||
import u from 'updeep';
|
||||
|
||||
import { Updux } from '../src/index.js';
|
||||
|
||||
const todos = new Updux({
|
||||
initial: [],
|
||||
actions: {
|
||||
setNbrTodos: null,
|
||||
addTodo: null,
|
||||
},
|
||||
mutations: {
|
||||
addTodo: todo => todos => [ ...todos, todo ],
|
||||
},
|
||||
reactions: [
|
||||
({dispatch}) => todos => dispatch.setNbrTodos(todos.length)
|
||||
],
|
||||
});
|
||||
|
||||
const myDux = new Updux({
|
||||
initial: {
|
||||
nbrTodos: 0
|
||||
},
|
||||
subduxes: {
|
||||
todos,
|
||||
},
|
||||
mutations: {
|
||||
setNbrTodos: nbrTodos => u({ nbrTodos })
|
||||
}
|
||||
});
|
||||
|
||||
test( "basic tests", async () => {
|
||||
const store = myDux.createStore();
|
||||
|
||||
store.dispatch.addTodo('one');
|
||||
store.dispatch.addTodo('two');
|
||||
|
||||
expect(store.getState().nbrTodos).toEqual(2);
|
||||
});
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
import { test, expect } from 'vitest';
|
||||
|
||||
import { Updux } from '../src/index.js';
|
||||
|
||||
test( 'selectors', () => {
|
||||
const dux = new Updux({
|
||||
initial: { a: 1, b: 2 },
|
||||
selectors: {
|
||||
getA: ({a}) => a,
|
||||
getBPlus: ({b}) => addition => b + addition,
|
||||
},
|
||||
subduxes: {
|
||||
subbie: new Updux({
|
||||
initial: { d: 3 },
|
||||
selectors: {
|
||||
getD: ({d}) => d
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
const store = dux.createStore();
|
||||
|
||||
expect( store.getState.getA() ).toEqual(1);
|
||||
expect( store.getState.getBPlus(7) ).toEqual(9);
|
||||
expect( store.getState.getD() ).toEqual(3);
|
||||
} );
|
|
@ -0,0 +1,91 @@
|
|||
import { test, expect } from 'vitest';
|
||||
|
||||
import u from 'updeep';
|
||||
import R from 'remeda';
|
||||
|
||||
import { Updux } from '../src/index.js';
|
||||
|
||||
const nextIdDux = new Updux({
|
||||
initial: 1,
|
||||
actions: {
|
||||
incrementNextId: null,
|
||||
},
|
||||
selectors: {
|
||||
getNextId: state => state
|
||||
},
|
||||
mutations: {
|
||||
incrementNextId: () => state => state + 1,
|
||||
}
|
||||
});
|
||||
|
||||
const matches = conditions => target => Object.entries(conditions).every(
|
||||
([key,value]) => typeof value === 'function' ? value(target[key]) : target[key] === value
|
||||
);
|
||||
|
||||
const todoDux = new Updux({
|
||||
initial: {
|
||||
id: 0,
|
||||
description: "",
|
||||
done: false,
|
||||
},
|
||||
actions: {
|
||||
todoDone: null,
|
||||
},
|
||||
mutations: {
|
||||
todoDone: id => u.if( matches({id}), { done: true })
|
||||
},
|
||||
selectors: {
|
||||
desc: R.prop('description'),
|
||||
}
|
||||
});
|
||||
|
||||
const todosDux = new Updux({
|
||||
initial: [],
|
||||
subduxes: {
|
||||
'*': todoDux
|
||||
},
|
||||
actions: {
|
||||
addTodoWithId: (description, id) => ({description, id} )
|
||||
},
|
||||
findSelectors: {
|
||||
getTodoById: state => id => state.find(matches({id}))
|
||||
},
|
||||
mutations: {
|
||||
addTodoWithId: todo => todos => [...todos, todo]
|
||||
}
|
||||
});
|
||||
|
||||
const mainDux = new Updux({
|
||||
subduxes: {
|
||||
nextId: nextIdDux,
|
||||
todos: todosDux,
|
||||
},
|
||||
actions: {
|
||||
addTodo: null
|
||||
},
|
||||
effects: {
|
||||
addTodo: ({ getState, dispatch }) => next => action => {
|
||||
const id = getState.getNextId();
|
||||
|
||||
dispatch.incrementNextId()
|
||||
|
||||
next(action);
|
||||
|
||||
dispatch.addTodoWithId( action.payload, id );
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const store = mainDux.createStore();
|
||||
|
||||
|
||||
test( "basic tests", () => {
|
||||
|
||||
const myDesc = 'do the thing';
|
||||
store.dispatch.addTodo(myDesc);
|
||||
|
||||
expect( store.getState.getTodoById(1).desc() ).toEqual(myDesc);
|
||||
|
||||
|
||||
|
||||
});
|
595
docs/tutorial.md
|
@ -3,262 +3,125 @@
|
|||
This tutorial walks you through the features of `Updux` using the
|
||||
time-honored example of the implementation of Todo list store.
|
||||
|
||||
This tutorial assumes that our project is written in TypeScript, and
|
||||
that we are using [updeep](https://www.npmjs.com/package/updeep) to
|
||||
help with immutability and deep merging and [ts-action][] to manage our
|
||||
actions. This is the recommended setup, but
|
||||
neither of those two architecture
|
||||
decisions are mandatory; Updux is equally usable in a pure-JavaScript setting,
|
||||
and `updeep` can easily be substitued with, say, [immer][], [lodash][], or even
|
||||
just plain JavaScript. Eventually, I plan to write a version of this tutorial
|
||||
with all those different configurations.
|
||||
|
||||
Also, the code used here is also available in the project repository, in the
|
||||
`src/tutorial` directory.
|
||||
We'll be using
|
||||
[updeep](https://www.npmjs.com/package/updeep) to
|
||||
help with immutability and deep merging,
|
||||
but that's totally optional. If `updeep` is not your bag,
|
||||
it can easily be substitued with, say, [immer][], [lodash][], or even
|
||||
plain JavaScript.
|
||||
|
||||
## Definition of the state
|
||||
|
||||
First thing first: let's define the type of our store:
|
||||
To begin with, let's define that has nothing but an initial state.
|
||||
|
||||
```
|
||||
type Todo = {
|
||||
id: number;
|
||||
description: string;
|
||||
done: boolean;
|
||||
};
|
||||
```js
|
||||
import { Updux } from 'updux';
|
||||
|
||||
type TodoStore = {
|
||||
next_id: number;
|
||||
todos: Todo[];
|
||||
};
|
||||
```
|
||||
|
||||
With that, let's create our very first Updux:
|
||||
|
||||
```
|
||||
import Updux from 'updux';
|
||||
|
||||
const todosUpdux = new Updux({
|
||||
const todosDux = new Updux({
|
||||
initial: {
|
||||
next_id: 1,
|
||||
todos: [],
|
||||
} as TodoStore
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Note that we explicitly cast the initial state as `as TodoStore`. This lets
|
||||
Updux know what is the store's state.
|
||||
|
||||
This being said, congrats! You have written your first Updux object. It
|
||||
Congrats! You have written your first Updux object. It
|
||||
doesn't do a lot, but you can already create a store out of it, and its
|
||||
initial state will be automatically set:
|
||||
|
||||
```
|
||||
const store = todosUpdux.createStore();
|
||||
```js
|
||||
const store = todosDux.createStore();
|
||||
|
||||
console.log(store.getState());
|
||||
// { next_id: 1, todos: [] }
|
||||
console.log(store.getState()); // prints { next_id: 1, todos: [] }
|
||||
```
|
||||
|
||||
## Add actions
|
||||
|
||||
This is all good, but a little static. Let's add actions!
|
||||
|
||||
```
|
||||
import { action, payload } from 'ts-action';
|
||||
|
||||
const add_todo = action('add_todo', payload<string>() );
|
||||
const todo_done = action('todo_done', payload<number>() );
|
||||
```
|
||||
|
||||
Now, there is a lot of ways to add actions to a Updux object.
|
||||
|
||||
It can be defined when the object is created:
|
||||
|
||||
```
|
||||
const todosUpdux = new Updux({
|
||||
actions: {
|
||||
add_todo,
|
||||
todo_done,
|
||||
```js
|
||||
const todosDux = new Updux({
|
||||
initial: {
|
||||
next_id: 1,
|
||||
todos: [],
|
||||
},
|
||||
{
|
||||
addTodo: null,
|
||||
todoDone: null,
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
It can be done via the method `addAction`:
|
||||
|
||||
```
|
||||
todosUpdux.addAction(add_todo);
|
||||
```
|
||||
|
||||
Or it can be directly used in the definition of a mutation or effect, and will
|
||||
be automatically added to the Updux.
|
||||
|
||||
```
|
||||
todosUpdux.addMutation( add_todo, todoMutation );
|
||||
```
|
||||
|
||||
For TypeScript projects I recommend declaring the actions as part of the
|
||||
configuration passed to the constructors, as it makes them accessible to the class
|
||||
at compile-time, and allows Updux to auto-add them to its aggregated `actions` type.
|
||||
|
||||
```
|
||||
const todosUpdux = new Updux({
|
||||
actions: {
|
||||
add_todo,
|
||||
}
|
||||
});
|
||||
|
||||
todosUpdux.addAction(todo_done);
|
||||
|
||||
// only `add_todo` is visible to the type
|
||||
type MyActions = typeof todosUpdux.actions;
|
||||
// { add_todo: Function }
|
||||
|
||||
// but both actions are accessible at runtime
|
||||
const myAction = ( todosUpdux.actions as any).todo_done(1);
|
||||
```
|
||||
|
||||
### Accessing actions
|
||||
|
||||
Once an action is defined, its creator is accessible via the `actions` accessor.
|
||||
|
||||
```js
|
||||
console.log( todosDux.actions.addTodo('write tutorial') );
|
||||
// prints { type: 'addTodo', payload: 'write tutorial' }
|
||||
```
|
||||
console.log( todosUpdux.actions.add_todo('write tutorial') );
|
||||
// { type: 'add_todo', payload: 'write tutorial' }
|
||||
```
|
||||
|
||||
### What is an action?
|
||||
|
||||
In this tutorial we use `ts-action` for all the work, but under the hood Updux defines actions via
|
||||
their creators, which are expected to be:
|
||||
|
||||
1. Functions,
|
||||
2. returning a plain object of the format `{ type: string; payload?: unknown }`.
|
||||
3. with an additional property `type`, which is also the action type.
|
||||
|
||||
For example, this is a perfectly cromulent action:
|
||||
|
||||
```
|
||||
const add_todo = description => ({ type: 'add_todo', payload: description});
|
||||
add_todo.type = 'add_todo';
|
||||
```
|
||||
|
||||
## Mutations
|
||||
|
||||
Actions that don't do anything are not fun. The transformations typically
|
||||
done by a Redux's reducer are called 'mutations' in Updux. A mutation is a
|
||||
function with the following signature:
|
||||
|
||||
```
|
||||
( payload, action ) => state => {
|
||||
// ... stuff done here
|
||||
return new_state;
|
||||
}
|
||||
```
|
||||
|
||||
The inversion and chaining of parameters from the usual Redux reducer's
|
||||
signature is there to work with `updeep`'s curried nature. The expansion of
|
||||
the usual `action` into `(payload, action)` is present because in most cases
|
||||
`payload` is what we're interested in. So why not make it easily available?
|
||||
|
||||
### Adding a mutation
|
||||
|
||||
As for the actions, a mutation can be defined as part of the Updux
|
||||
init arguments:
|
||||
Mutations are the reducing functions associated to actions. They
|
||||
are defined via the `setMutation` method:
|
||||
|
||||
|
||||
```js
|
||||
todosDux.setMutation( 'addTodo', description => ({next_id: id, todos}) => ({
|
||||
next_id: 1 + id,
|
||||
todos: [...todos, { description, id, done: false }]
|
||||
}));
|
||||
```
|
||||
const add_todo_mutation = description => ({next_id: id, todos}) => {
|
||||
return {
|
||||
next_id: 1 + id,
|
||||
todos: [...todos, { description, id, done: false }]
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const todosUpdux = new Updux({
|
||||
actions: { add_todo },
|
||||
mutations: [
|
||||
[ add_todo, add_todo_mutation ]
|
||||
]
|
||||
});
|
||||
```
|
||||
|
||||
or via the method `addMutation`:
|
||||
|
||||
```
|
||||
todos.addMutation( add_todo, description => ({next_id: id, todos}) => {
|
||||
return {
|
||||
next_id: 1 + id,
|
||||
todos: [...todos, { description, id, done: false }]
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
This time around, if the project is using TypeScript then the addition of
|
||||
mutations via `addMutation` is encouraged, as the method signature
|
||||
has visibility of the types of the action and state.
|
||||
|
||||
### Leftover mutation
|
||||
|
||||
A mutation with the special action `*` will match any action that haven't been
|
||||
explicitly dealt with with any other defined mutation.
|
||||
|
||||
```
|
||||
todosUpdux.addMutation( '*', (payload,action) => state => {
|
||||
console.log("hey, action has no mutation! ", action.type);
|
||||
});
|
||||
```
|
||||
|
||||
## Effects
|
||||
|
||||
In addition to mutations, Updux also provides action-specific middleware, here
|
||||
called effects.
|
||||
|
||||
Effects use the usual Redux middleware signature:
|
||||
Effects use the usual Redux middleware signature, plus a few goodies.
|
||||
The `getState` and `dispatch` functions are augmented with the dux selectors,
|
||||
and actions, respectively. The selectors and actions are also available
|
||||
from the api object.
|
||||
|
||||
```
|
||||
```js
|
||||
import u from 'updeep';
|
||||
import { action, Updux } from 'updux';
|
||||
|
||||
// we want to decouple the increment of next_id and the creation of
|
||||
// a new todo. So let's use a new version of the action 'add_todo'.
|
||||
// a new todo. So let's use a new version of the action 'addTodo'.
|
||||
|
||||
const add_todo_with_id = action('add_todo_with_id', payload<{description: string; id?: number}>() );
|
||||
const inc_next_id = action('inc_next_id');
|
||||
const addTodoWithId = action('addTodoWithId');
|
||||
const incNextId = action('incNextId');
|
||||
const addTodo = action('addTodo');
|
||||
|
||||
const populate_next_id = ({ getState, dispatch }) => next => action => {
|
||||
const { next_id: id } = getState();
|
||||
const addTodoEffect = ({ getState, dispatch }) => next => action => {
|
||||
const id = getState.nextId();
|
||||
|
||||
dispatch.incNextId();
|
||||
|
||||
dispatch(inc_next_id());
|
||||
next(action);
|
||||
dispatch( add_todo_with_id({ description: action.payload, id }) );
|
||||
|
||||
dispatch.addTodoWithId({ description: action.payload, id });
|
||||
}
|
||||
```
|
||||
|
||||
And just like mutations, they can be defined as part of the init
|
||||
configuration, or after via the method `addEffect`:
|
||||
|
||||
```
|
||||
const todosUpdux = new Updux({
|
||||
actions: { add_todo, inc_next_id },
|
||||
effects: [
|
||||
[ add_todo, populate_next_id ]
|
||||
]
|
||||
})
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```
|
||||
const todosUpdux = new Updux({
|
||||
actions: { add_todo, inc_next_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
|
||||
}
|
||||
});
|
||||
|
||||
todosUpdux.addEffect( add_todo, populate_next_id );
|
||||
```
|
||||
const store = todosDux.createStore();
|
||||
|
||||
As for the mutations, for TypeScript projects
|
||||
the use of `addEffect` is prefered, as the method gives visibility to the
|
||||
action and state types.
|
||||
store.dispatch.addTodo('Do the thing');
|
||||
```
|
||||
|
||||
### Catch-all effect
|
||||
|
||||
|
@ -271,19 +134,14 @@ todosUpdux.addEffect('*', () => next => action => {
|
|||
});
|
||||
```
|
||||
|
||||
## Selectors
|
||||
## Adding selectors
|
||||
|
||||
Selectors can be defined to get data derived from the state.
|
||||
|
||||
### Adding selectors
|
||||
|
||||
From now you should know the drill: selectors can be defined at construction
|
||||
time or via `addSelector`.
|
||||
time or via `setSelector`.
|
||||
|
||||
```
|
||||
import fp from 'lodash/fp';
|
||||
|
||||
const getTodoById = ({todos}) => id => fp.find({id},todos);
|
||||
const getTodoById = ({todos}) => targetId => todos.find(({id}) => id === targetId);
|
||||
|
||||
const todosUpdux = new Updux({
|
||||
selectors: {
|
||||
|
@ -295,287 +153,212 @@ const todosUpdux = new Updux({
|
|||
or
|
||||
|
||||
```
|
||||
todosUpdux.addSelector('getTodoById', ({todos}) => id => fp.find({id},todos));
|
||||
todosDux.setSelector('getTodoById', getTodoById);
|
||||
```
|
||||
|
||||
Here the declaration as part of the constructor configuration is prefered.
|
||||
Whereas the `addSelector` will provide the state's type as part of its
|
||||
signature, declaring the selectors via the constructors will make them visible
|
||||
via the type of the accessors `selectors`.
|
||||
|
||||
### Accessing selectors
|
||||
|
||||
Selectors are available via the accessor `selectors`.
|
||||
The `getState` method of a dux store is augmented
|
||||
with its selectors, with the first call for the state already
|
||||
called in for you.
|
||||
|
||||
```
|
||||
const store = todosUpdux.createStore();
|
||||
```js
|
||||
const store = todosDux.createStore();
|
||||
|
||||
console.log(
|
||||
todosUpdux.selectors.getTodoById( store.getState() )(1)
|
||||
todosUpdux.getState.getTodoById(1)
|
||||
);
|
||||
```
|
||||
|
||||
## Subduxes
|
||||
|
||||
Now that we have all the building blocks, we can embark on the last, and best,
|
||||
part of Updux: its recursive nature.
|
||||
Now that we have all the building blocks, we can embark on the last and
|
||||
funkiest part of Updux: its recursive nature.
|
||||
|
||||
### Recap: the Todos updux, undivided
|
||||
### Recap: the Todos dux, undivided
|
||||
|
||||
Upduxes can be divided into sub-upduxes that deal with the various parts of
|
||||
the global state. This is better understood by working out an example, so
|
||||
let's recap on the Todos Updux we have so far:
|
||||
let's recap on the Todos dux we have so far:
|
||||
|
||||
```
|
||||
```js
|
||||
import Updux from 'updux';
|
||||
import { action, payload } from 'ts-action';
|
||||
import u from 'updeep';
|
||||
import fp from 'lodash/fp';
|
||||
|
||||
type Todo = {
|
||||
id: number;
|
||||
description: string;
|
||||
done: boolean;
|
||||
};
|
||||
|
||||
type TodoStore = {
|
||||
next_id: number;
|
||||
todos: Todo[];
|
||||
};
|
||||
|
||||
const add_todo = action('add_todo', payload<string>() );
|
||||
const add_todo_with_id = action('add_todo_with_id',
|
||||
payload<{ description: string; id: number }>() );
|
||||
const todo_done = action('todo_done', payload<number>() );
|
||||
const increment_next_id = action('increment_next_id');
|
||||
|
||||
const todosUpdux = new Updux({
|
||||
const todosDux = new Updux({
|
||||
initial: {
|
||||
next_id: 1,
|
||||
nextId: 1,
|
||||
todos: [],
|
||||
} as TodoStore,
|
||||
},
|
||||
actions: {
|
||||
add_todo,
|
||||
add_todo_with_id,
|
||||
todo_done,
|
||||
increment_next_id,
|
||||
addTodo: null,
|
||||
addTodoWithId: (description, id) => ({description, id, done: false}),
|
||||
todoDone: null,
|
||||
incNextId: null,
|
||||
},
|
||||
selectors: {
|
||||
getTodoById: ({todos}) => id => fp.find({id},todos)
|
||||
},
|
||||
mutations: {
|
||||
addTodoWithId: todo =>
|
||||
u.updateIn( 'todos', todos => [ ...todos, todo] ),
|
||||
incrementNextId: () => u({ nextId: fp.add(1) }),
|
||||
todoDone: (id) => u.updateIn('todos',
|
||||
u.map( u.if( fp.matches({id}), todo => u({done: true}, todo) ) )
|
||||
),
|
||||
},
|
||||
effects: {
|
||||
addTodo: ({ getState, dispatch }) => next => action => {
|
||||
const { nextId: id } = getState();
|
||||
|
||||
dispatch.incNextId();
|
||||
|
||||
next(action);
|
||||
|
||||
dispatch.addTodoWithId(action.payload, id);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
todosUpdux.addMutation( add_todo_with_id, payload =>
|
||||
u.updateIn( 'todos', todos => [ ...todos, { ...payload, done: false }] )
|
||||
);
|
||||
|
||||
todosUpdux.addMutation( increment_next_id, () => u({ next_id: i => i + 1 }) );
|
||||
|
||||
todosUpdux.addMutation( todo_done, id => u.updateIn(
|
||||
'todos', u.map( u.if( fp.matches({id}), todo => u({done: true}, todo) ) )
|
||||
) );
|
||||
|
||||
todosUpdux.addEffect( add_todo, ({ getState, dispatch }) => next => action => {
|
||||
const { next_id: id } = getState();
|
||||
|
||||
dispatch(inc_next_id());
|
||||
|
||||
next(u.updateIn('payload', {id}, action))
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
This store has two main components: the `next_id`, and the `todos` collection.
|
||||
The `todos` collection is itself composed of the individual `todo`s. So let's
|
||||
This store has two main components: the `nextId`, and the `todos` collection.
|
||||
The `todos` collection is itself composed of the individual `todo`s. Let's
|
||||
create upduxes for each of those.
|
||||
|
||||
### Next_id updux
|
||||
### NextId dux
|
||||
|
||||
```
|
||||
// dux/next_id.ts
|
||||
// dux/nextId.js
|
||||
|
||||
import Updux from 'updux';
|
||||
import { action, payload } from 'ts-action';
|
||||
import { Updux } from 'updux';
|
||||
import u from 'updeep';
|
||||
import fp from 'lodash/fp';
|
||||
|
||||
const increment_next_id = action('increment_next_id');
|
||||
|
||||
const updux = new Updux({
|
||||
export default new Updux({
|
||||
initial: 1,
|
||||
actions: {
|
||||
increment_next_id,
|
||||
incrementNextId: null,
|
||||
},
|
||||
selectors: {
|
||||
getNextId: state => state
|
||||
},
|
||||
mutations: {
|
||||
incrementNextId: () => state => state + 1,
|
||||
}
|
||||
});
|
||||
|
||||
updux.addMutation( increment_next_id, () => fp.add(1) );
|
||||
|
||||
export default updux.asDux;
|
||||
|
||||
```
|
||||
|
||||
Notice that we didn't have to specify the type of `initial`;
|
||||
TypeScript figures by itself that it's a number.
|
||||
|
||||
Also, note that we're exporting the output of the accessor `asDux` instead of
|
||||
the updux object itself. See the upcoming section 'Exporting upduxes' for the rationale.
|
||||
|
||||
### Todo updux
|
||||
|
||||
```
|
||||
// dux/todos/todo/index.ts
|
||||
|
||||
import Updux from 'updux';
|
||||
import { action, payload } from 'ts-action';
|
||||
import { Updux } from 'updux';
|
||||
import u from 'updeep';
|
||||
import fp from 'lodash/fp';
|
||||
|
||||
type Todo = {
|
||||
id: number;
|
||||
description: string;
|
||||
done: boolean;
|
||||
};
|
||||
|
||||
const todo_done = action('todo_done', payload<number>() );
|
||||
|
||||
const updux = new Updux({
|
||||
export default new Updux({
|
||||
initial: {
|
||||
next_id: 0,
|
||||
id: 0,
|
||||
description: "",
|
||||
done: false,
|
||||
} as Todo,
|
||||
},
|
||||
actions: {
|
||||
todo_done
|
||||
todoDone: null,
|
||||
},
|
||||
mutations: {
|
||||
todoDone: id => u.if( fp.matches({id}), { done: true }) )
|
||||
},
|
||||
selectors: {
|
||||
desc: ({description}) => description,
|
||||
}
|
||||
});
|
||||
|
||||
updux.addMutation( todo_done, id => u.if( fp.matches({id}), { done: true }) );
|
||||
|
||||
export default updux.asDux;
|
||||
|
||||
```
|
||||
|
||||
### Todos updux
|
||||
|
||||
```
|
||||
// dux/todos/index.ts
|
||||
// dux/todos/index.js
|
||||
|
||||
import Updux, { DuxState } from 'updux';
|
||||
import { action, payload } from 'ts-action';
|
||||
import { Updux } from 'updux';
|
||||
import u from 'updeep';
|
||||
import fp from 'lodash/fp';
|
||||
|
||||
import todo from './todo';
|
||||
import todo from './todo/index.js';
|
||||
|
||||
type TodoState = DuxState<typeof todo>;
|
||||
|
||||
const add_todo_with_id = action('add_todo_with_id',
|
||||
payload<{ description: string; id: number }>()
|
||||
);
|
||||
|
||||
const updux = new Updux({
|
||||
initial: [] as Todo[],
|
||||
export default new Updux({
|
||||
initial: [],
|
||||
subduxes: {
|
||||
'*': todo.upreducer
|
||||
'*': todoDux
|
||||
},
|
||||
actions: {
|
||||
add_todo_with_id,
|
||||
addTodoWithId: (description, id) => ({description, id} )
|
||||
},
|
||||
selectors: {
|
||||
findSelectors: {
|
||||
getTodoById: state => id => fp.find({id},state)
|
||||
},
|
||||
mutations: {
|
||||
addTodoWithId: todo =>
|
||||
todos => [ ...todos, todo ]
|
||||
}
|
||||
});
|
||||
|
||||
todosUpdux.addMutation( add_todo_with_id, payload =>
|
||||
todos => [ ...todos, { ...payload, done: false }]
|
||||
);
|
||||
|
||||
export default updux.asDux;
|
||||
```
|
||||
|
||||
Note the special '\*' subdux key used here. This
|
||||
allows the updux to map every item present in its
|
||||
state to a `todo` updux. See [this recipe](/recipes?id=mapping-a-mutation-to-all-values-of-a-state) for details.
|
||||
We could also have written the updux as:
|
||||
|
||||
```
|
||||
const updux = new Updux({
|
||||
initial: [] as Todo[],
|
||||
actions: {
|
||||
add_todo_with_id,
|
||||
},
|
||||
selectors: {
|
||||
getTodoById: state => id => fp.find({id},state)
|
||||
},
|
||||
mutations: {
|
||||
'*': (payload,action) => state => u.map( todo.reducer(state, action) )
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Note how we are using the `upreducer` accessor in the first case (which yields
|
||||
a reducer for the dux using the signature `(payload,action) => state => new_state`) and `reducer` in the second case (which yield an equivalent
|
||||
reducer using the classic signature `(state,action) => new_state`).
|
||||
|
||||
### Main store
|
||||
|
||||
```
|
||||
// dux/index.ts
|
||||
// dux/index.js
|
||||
|
||||
import Updux from 'updux';
|
||||
|
||||
import todos from './todos';
|
||||
import next_id from './next_id';
|
||||
import nextId from './next_id';
|
||||
|
||||
const add_todo = action('add_todo', payload<string>() );
|
||||
|
||||
const updux = new Updux({
|
||||
export new Updux({
|
||||
subduxes: {
|
||||
next_id,
|
||||
nextId,
|
||||
todos,
|
||||
},
|
||||
actions: {
|
||||
add_todo
|
||||
addTodo: null
|
||||
},
|
||||
effects: {
|
||||
addTodo: ({ getState, dispatch }) => next => action => {
|
||||
const id = getState.getNextId();
|
||||
|
||||
dispatch.incrementNextId()
|
||||
|
||||
next(action);
|
||||
|
||||
dispatch.addTodoWithId( action.payload, id );
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
todos.addEffect( add_todo, ({ getState, dispatch }) => next => action => {
|
||||
const id = updux.selectors.getNextId( getState() );
|
||||
|
||||
dispatch(updux.actions.inc_next_id());
|
||||
|
||||
next(action);
|
||||
|
||||
dispatch( updux.actions.add_todo_with_id({ description: action.payload, id }) );
|
||||
});
|
||||
|
||||
export default updux.asDux;
|
||||
|
||||
```
|
||||
|
||||
Tadah! We had to define the `add_todo` effect at the top level as it needs to
|
||||
access the `getNextId` selector from `next_id` and the `add_todo_with_id`
|
||||
Tadah! We had to define the `addTodo` effect at the top level as it needs to
|
||||
access the `getNextId` selector from `nextId` and the `addTodoWithId`
|
||||
action from the `todos`.
|
||||
|
||||
Note that the `getNextId` selector still gets the
|
||||
right value; when aggregating subduxes selectors Updux auto-wraps them to
|
||||
access the right slice of the top object. i.e., the `getNextId` selector
|
||||
at the main level is actually defined as:
|
||||
access the right slice of the top object. ```
|
||||
|
||||
## Reactions
|
||||
|
||||
Reactions -- aka Redux's subscriptions -- can be added to a updux store via the initial config
|
||||
or the method `addSubscription`. The signature of a reaction is:
|
||||
|
||||
```
|
||||
const getNextId = state => next_id.selectors.getNextId(state.next_id);
|
||||
```
|
||||
|
||||
## Subscriptions
|
||||
|
||||
Subscriptions can be added by default to a updux store via the initial config
|
||||
or the method `addSubscription`. The signature of a subscription is:
|
||||
|
||||
```
|
||||
(store) => (state,unsubscribe) => {
|
||||
(storeApi) => (state, previousState, unsubscribe) => {
|
||||
...
|
||||
}
|
||||
```
|
||||
|
@ -591,46 +374,34 @@ local `state` changed since their last invocation.
|
|||
Example:
|
||||
|
||||
```
|
||||
const set_nbr_todos = action('set_nbr_todos', payload() );
|
||||
|
||||
const todos = dux({
|
||||
const todos = new Updux({
|
||||
initial: [],
|
||||
subscriptions: [
|
||||
({dispatch}) => todos => dispatch(set_nbr_todos(todos.length))
|
||||
actions: {
|
||||
setNbrTodos: null,
|
||||
addTodo: null,
|
||||
},
|
||||
mutations: {
|
||||
addTodo: todo => todos => [ ...todos, todo ],
|
||||
},
|
||||
reactions: [
|
||||
({dispatch}) => todos => dispatch.setNbrTodos(todos.length)
|
||||
],
|
||||
});
|
||||
|
||||
const myDux = dux({
|
||||
const myDux = new Updux({
|
||||
initial: {
|
||||
nbr_todos: 0
|
||||
nbrTodos: 0
|
||||
},
|
||||
subduxes: {
|
||||
todos,
|
||||
},
|
||||
mutations: [
|
||||
[ set_nbr_todos, nbr_todos => u({nbr_todos}) ]
|
||||
]
|
||||
})
|
||||
mutations: {
|
||||
setNbrTodos: nbrTodos => u({ nbrTodos })
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Exporting upduxes
|
||||
|
||||
As a general rule, don't directly export your upduxes, but rather use the accessor `asDux`.
|
||||
|
||||
```
|
||||
const updux = new Updux({ ... });
|
||||
|
||||
...
|
||||
|
||||
export default updux.asDux;
|
||||
```
|
||||
|
||||
`asDux` returns an immutable copy of the attributes of the updux. Exporting
|
||||
this instead of the updux itself prevents unexpected modifications done
|
||||
outside of the updux declaration file. More importantly, the output of
|
||||
`asDux` has more precise typing, which in result results in better typing of
|
||||
parent upduxes using the dux as one of its subduxes.
|
||||
|
||||
[immer]: https://www.npmjs.com/package/immer
|
||||
[lodash]: https://www.npmjs.com/package/lodash
|
||||
[ts-action]: https://www.npmjs.com/package/ts-action
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
import { test, expect } from 'vitest';
|
||||
|
||||
import { Updux } from '../src/index.js';
|
||||
|
||||
test( "basic checks", async () => {
|
||||
|
||||
|
||||
const todosDux = new Updux({
|
||||
initial: {
|
||||
next_id: 1,
|
||||
todos: [],
|
||||
},
|
||||
actions: {
|
||||
addTodo: null,
|
||||
todoDone: null,
|
||||
}
|
||||
});
|
||||
|
||||
const store = todosDux.createStore();
|
||||
|
||||
expect(store.getState()).toEqual({ next_id: 1, todos: [] });
|
||||
|
||||
expect(store.actions.addTodo("learn updux")).toMatchObject({
|
||||
type: 'addTodo', payload: 'learn updux'
|
||||
})
|
||||
});
|
|
@ -1,228 +0,0 @@
|
|||
[updux - v1.2.0](README.md) › [Globals](globals.md)
|
||||
|
||||
# updux - v1.2.0
|
||||
|
||||
# What's Updux?
|
||||
|
||||
So, I'm a fan of [Redux](https://redux.js.org). Two days ago I discovered
|
||||
[rematch](https://rematch.github.io/rematch) alonside a few other frameworks built atop Redux.
|
||||
|
||||
It has a couple of pretty good ideas that removes some of the
|
||||
boilerplate. Keeping mutations and asynchronous effects close to the
|
||||
reducer definition? Nice. Automatically infering the
|
||||
actions from the said mutations and effects? Genius!
|
||||
|
||||
But it also enforces a flat hierarchy of reducers -- where
|
||||
is the fun in that? And I'm also having a strong love for
|
||||
[Updeep](https://github.com/substantial/updeep), so I want reducer state updates to leverage the heck out of it.
|
||||
|
||||
All that to say, say hello to `Updux`. Heavily inspired by `rematch`, but twisted
|
||||
to work with `updeep` and to fit my peculiar needs. It offers features such as
|
||||
|
||||
* Mimic the way VueX has mutations (reducer reactions to specific actions) and
|
||||
effects (middleware reacting to actions that can be asynchronous and/or
|
||||
have side-effects), so everything pertaining to a store are all defined
|
||||
in the space place.
|
||||
* Automatically gather all actions used by the updux's effects and mutations,
|
||||
and makes then accessible as attributes to the `dispatch` object of the
|
||||
store.
|
||||
* Mutations have a signature that is friendly to Updux and Immer.
|
||||
* Also, the mutation signature auto-unwrap the payload of the actions for you.
|
||||
* TypeScript types.
|
||||
|
||||
Fair warning: this package is still very new, probably very buggy,
|
||||
definitively very badly documented, and very subject to changes. Caveat
|
||||
Maxima Emptor.
|
||||
|
||||
# Synopsis
|
||||
|
||||
```
|
||||
import updux from 'updux';
|
||||
|
||||
import otherUpdux from './otherUpdux';
|
||||
|
||||
const {
|
||||
initial,
|
||||
reducer,
|
||||
actions,
|
||||
middleware,
|
||||
createStore,
|
||||
} = new Updux({
|
||||
initial: {
|
||||
counter: 0,
|
||||
},
|
||||
subduxes: {
|
||||
otherUpdux,
|
||||
},
|
||||
mutations: {
|
||||
inc: ( increment = 1 ) => u({counter: s => s + increment })
|
||||
},
|
||||
effects: {
|
||||
'*' => api => next => action => {
|
||||
console.log( "hey, look, an action zoomed by!", action );
|
||||
next(action);
|
||||
};
|
||||
},
|
||||
actions: {
|
||||
customAction: ( someArg ) => ({
|
||||
type: "custom",
|
||||
payload: { someProp: someArg }
|
||||
}),
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
const store = createStore();
|
||||
|
||||
store.dispatch.inc(3);
|
||||
```
|
||||
|
||||
# Description
|
||||
|
||||
Full documentation can be [found here](https://yanick.github.io/updux/docs/).
|
||||
|
||||
## Exporting upduxes
|
||||
|
||||
If you are creating upduxes that will be used as subduxes
|
||||
by other upduxes, or as
|
||||
[ducks](https://github.com/erikras/ducks-modular-redux)-like containers, I
|
||||
recommend that you export the Updux instance as the default export:
|
||||
|
||||
```
|
||||
import Updux from 'updux';
|
||||
|
||||
const updux = new Updux({ ... });
|
||||
|
||||
export default updux;
|
||||
```
|
||||
|
||||
Then you can use them as subduxes like this:
|
||||
|
||||
```
|
||||
import Updux from 'updux';
|
||||
import foo from './foo'; // foo is an Updux
|
||||
import bar from './bar'; // bar is an Updux as well
|
||||
|
||||
const updux = new Updux({
|
||||
subduxes: {
|
||||
foo, bar
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Or if you want to use it:
|
||||
|
||||
```
|
||||
import updux from './myUpdux';
|
||||
|
||||
const {
|
||||
reducer,
|
||||
actions: { doTheThing },
|
||||
createStore,
|
||||
middleware,
|
||||
} = updux;
|
||||
```
|
||||
|
||||
## Mapping a mutation to all values of a state
|
||||
|
||||
Say you have a `todos` state that is an array of `todo` sub-states. It's easy
|
||||
enough to have the main reducer maps away all items to the sub-reducer:
|
||||
|
||||
```
|
||||
const todo = new Updux({
|
||||
mutations: {
|
||||
review: () => u({ reviewed: true}),
|
||||
done: () => u({done: true}),
|
||||
},
|
||||
});
|
||||
|
||||
const todos = new Updux({ initial: [] });
|
||||
|
||||
todos.addMutation(
|
||||
todo.actions.review,
|
||||
(_,action) => state => state.map( todo.upreducer(action) )
|
||||
);
|
||||
todos.addMutation(
|
||||
todo.actions.done,
|
||||
(id,action) => u.map(u.if(u.is('id',id), todo.upreducer(action))),
|
||||
);
|
||||
|
||||
```
|
||||
|
||||
But `updeep` can iterate through all the items of an array (or the values of
|
||||
an object) via the special key `*`. So the todos updux above could also be
|
||||
written:
|
||||
|
||||
```
|
||||
const todo = new Updux({
|
||||
mutations: {
|
||||
review: () => u({ reviewed: true}),
|
||||
done: () => u({done: true}),
|
||||
},
|
||||
});
|
||||
|
||||
const todos = new Updux({
|
||||
subduxes: { '*': todo },
|
||||
});
|
||||
|
||||
todos.addMutation(
|
||||
todo.actions.done,
|
||||
(id,action) => u.map(u.if(u.is('id',id), todo.upreducer(action))),
|
||||
true
|
||||
);
|
||||
```
|
||||
|
||||
The advantages being that the actions/mutations/effects of the subdux will be
|
||||
imported by the root updux as usual, and all actions that aren't being
|
||||
overridden by a sink mutation will trickle down automatically.
|
||||
|
||||
## Usage with Immer
|
||||
|
||||
While Updux was created with Updeep in mind, it also plays very
|
||||
well with [Immer](https://immerjs.github.io/immer/docs/introduction).
|
||||
|
||||
For example, taking this basic updux:
|
||||
|
||||
```
|
||||
import Updux from 'updux';
|
||||
|
||||
const updux = new Updux({
|
||||
initial: { counter: 0 },
|
||||
mutations: {
|
||||
add: (inc=1) => state => { counter: counter + inc }
|
||||
}
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
Converting it to Immer would look like:
|
||||
|
||||
```
|
||||
import Updux from 'updux';
|
||||
import { produce } from 'Immer';
|
||||
|
||||
const updux = new Updux({
|
||||
initial: { counter: 0 },
|
||||
mutations: {
|
||||
add: (inc=1) => produce( draft => draft.counter += inc ) }
|
||||
}
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
But since typing `produce` over and over is no fun, `groomMutations`
|
||||
can be used to wrap all mutations with it:
|
||||
|
||||
```
|
||||
import Updux from 'updux';
|
||||
import { produce } from 'Immer';
|
||||
|
||||
const updux = new Updux({
|
||||
initial: { counter: 0 },
|
||||
groomMutations: mutation => (...args) => produce( mutation(...args) ),
|
||||
mutations: {
|
||||
add: (inc=1) => draft => draft.counter += inc
|
||||
}
|
||||
});
|
||||
|
||||
```
|
|
@ -1,491 +0,0 @@
|
|||
[updux - v1.2.0](../README.md) › [Globals](../globals.md) › [Updux](updux.md)
|
||||
|
||||
# Class: Updux <**S, A, X, C**>
|
||||
|
||||
## Type parameters
|
||||
|
||||
▪ **S**
|
||||
|
||||
▪ **A**
|
||||
|
||||
▪ **X**
|
||||
|
||||
▪ **C**: *[UpduxConfig](../globals.md#upduxconfig)*
|
||||
|
||||
## Hierarchy
|
||||
|
||||
* **Updux**
|
||||
|
||||
## Index
|
||||
|
||||
### Constructors
|
||||
|
||||
* [constructor](updux.md#constructor)
|
||||
|
||||
### Properties
|
||||
|
||||
* [coduxes](updux.md#coduxes)
|
||||
* [groomMutations](updux.md#groommutations)
|
||||
* [subduxes](updux.md#subduxes)
|
||||
|
||||
### Accessors
|
||||
|
||||
* [_middlewareEntries](updux.md#_middlewareentries)
|
||||
* [actions](updux.md#actions)
|
||||
* [asDux](updux.md#asdux)
|
||||
* [createStore](updux.md#createstore)
|
||||
* [initial](updux.md#initial)
|
||||
* [middleware](updux.md#middleware)
|
||||
* [mutations](updux.md#mutations)
|
||||
* [reducer](updux.md#reducer)
|
||||
* [selectors](updux.md#selectors)
|
||||
* [subduxUpreducer](updux.md#subduxupreducer)
|
||||
* [upreducer](updux.md#upreducer)
|
||||
|
||||
### Methods
|
||||
|
||||
* [addAction](updux.md#addaction)
|
||||
* [addEffect](updux.md#addeffect)
|
||||
* [addMutation](updux.md#addmutation)
|
||||
* [addSelector](updux.md#addselector)
|
||||
|
||||
## Constructors
|
||||
|
||||
### constructor
|
||||
|
||||
\+ **new Updux**(`config`: C): *[Updux](updux.md)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type | Default | Description |
|
||||
------ | ------ | ------ | ------ |
|
||||
`config` | C | {} as C | an [UpduxConfig](../globals.md#upduxconfig) plain object |
|
||||
|
||||
**Returns:** *[Updux](updux.md)*
|
||||
|
||||
## Properties
|
||||
|
||||
### coduxes
|
||||
|
||||
• **coduxes**: *[Dux](../globals.md#dux)[]*
|
||||
|
||||
___
|
||||
|
||||
### groomMutations
|
||||
|
||||
• **groomMutations**: *function*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
▸ (`mutation`: [Mutation](../globals.md#mutation)‹S›): *[Mutation](../globals.md#mutation)‹S›*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`mutation` | [Mutation](../globals.md#mutation)‹S› |
|
||||
|
||||
___
|
||||
|
||||
### subduxes
|
||||
|
||||
• **subduxes**: *[Dictionary](../globals.md#dictionary)‹[Dux](../globals.md#dux)›*
|
||||
|
||||
## Accessors
|
||||
|
||||
### _middlewareEntries
|
||||
|
||||
• **get _middlewareEntries**(): *any[]*
|
||||
|
||||
**Returns:** *any[]*
|
||||
|
||||
___
|
||||
|
||||
### actions
|
||||
|
||||
• **get actions**(): *[DuxActions](../globals.md#duxactions)‹A, C›*
|
||||
|
||||
Action creators for all actions defined or used in the actions, mutations, effects and subduxes
|
||||
of the updux config.
|
||||
|
||||
Non-custom action creators defined in `actions` have the signature `(payload={},meta={}) => ({type,
|
||||
payload,meta})` (with the extra sugar that if `meta` or `payload` are not
|
||||
specified, that key won't be present in the produced action).
|
||||
|
||||
The same action creator can be included
|
||||
in multiple subduxes. However, if two different creators
|
||||
are included for the same action, an error will be thrown.
|
||||
|
||||
**`example`**
|
||||
|
||||
```
|
||||
const actions = updux.actions;
|
||||
```
|
||||
|
||||
**Returns:** *[DuxActions](../globals.md#duxactions)‹A, C›*
|
||||
|
||||
___
|
||||
|
||||
### asDux
|
||||
|
||||
• **get asDux**(): *object*
|
||||
|
||||
Returns a <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.
|
||||
|
||||
**`example`**
|
||||
|
||||
```
|
||||
const {
|
||||
createStore,
|
||||
upreducer,
|
||||
subduxes,
|
||||
coduxes,
|
||||
middleware,
|
||||
actions,
|
||||
reducer,
|
||||
mutations,
|
||||
initial,
|
||||
selectors,
|
||||
} = myUpdux.asDux;
|
||||
```
|
||||
|
||||
**Returns:** *object*
|
||||
|
||||
* **actions**: = this.actions
|
||||
|
||||
* **coduxes**: *object[]* = this.coduxes
|
||||
|
||||
* **createStore**(): *function*
|
||||
|
||||
* (`initial?`: S, `injectEnhancer?`: Function): *Store‹S› & object*
|
||||
|
||||
* **initial**: = this.initial
|
||||
|
||||
* **middleware**(): *function*
|
||||
|
||||
* (`api`: UpduxMiddlewareAPI‹S, X›): *function*
|
||||
|
||||
* (`next`: Function): *function*
|
||||
|
||||
* (`action`: A): *any*
|
||||
|
||||
* **mutations**(): *object*
|
||||
|
||||
* **reducer**(): *function*
|
||||
|
||||
* (`state`: S | undefined, `action`: [Action](../globals.md#action)): *S*
|
||||
|
||||
* **selectors**: = this.selectors
|
||||
|
||||
* **subduxes**(): *object*
|
||||
|
||||
* **upreducer**(): *function*
|
||||
|
||||
* (`action`: [Action](../globals.md#action)): *function*
|
||||
|
||||
* (`state`: S): *S*
|
||||
|
||||
___
|
||||
|
||||
### createStore
|
||||
|
||||
• **get createStore**(): *function*
|
||||
|
||||
Returns a `createStore` function that takes two argument:
|
||||
`initial` and `injectEnhancer`. `initial` is a custom
|
||||
initial state for the store, and `injectEnhancer` is a function
|
||||
taking in the middleware built by the updux object and allowing
|
||||
you to wrap it in any enhancer you want.
|
||||
|
||||
**`example`**
|
||||
|
||||
```
|
||||
const createStore = updux.createStore;
|
||||
|
||||
const store = createStore(initial);
|
||||
```
|
||||
|
||||
**Returns:** *function*
|
||||
|
||||
▸ (`initial?`: S, `injectEnhancer?`: Function): *Store‹S› & object*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`initial?` | S |
|
||||
`injectEnhancer?` | Function |
|
||||
|
||||
___
|
||||
|
||||
### initial
|
||||
|
||||
• **get initial**(): *AggDuxState‹S, C›*
|
||||
|
||||
**Returns:** *AggDuxState‹S, C›*
|
||||
|
||||
___
|
||||
|
||||
### middleware
|
||||
|
||||
• **get middleware**(): *[UpduxMiddleware](../globals.md#upduxmiddleware)‹AggDuxState‹S, C›, [DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C››*
|
||||
|
||||
Array of middlewares aggregating all the effects defined in the
|
||||
updux and its subduxes. Effects of the updux itself are
|
||||
done before the subduxes effects.
|
||||
Note that `getState` will always return the state of the
|
||||
local updux.
|
||||
|
||||
**`example`**
|
||||
|
||||
```
|
||||
const middleware = updux.middleware;
|
||||
```
|
||||
|
||||
**Returns:** *[UpduxMiddleware](../globals.md#upduxmiddleware)‹AggDuxState‹S, C›, [DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C››*
|
||||
|
||||
___
|
||||
|
||||
### mutations
|
||||
|
||||
• **get mutations**(): *[Dictionary](../globals.md#dictionary)‹[Mutation](../globals.md#mutation)‹S››*
|
||||
|
||||
Merge of the updux and subduxes mutations. If an action triggers
|
||||
mutations in both the main updux and its subduxes, the subduxes
|
||||
mutations will be performed first.
|
||||
|
||||
**Returns:** *[Dictionary](../globals.md#dictionary)‹[Mutation](../globals.md#mutation)‹S››*
|
||||
|
||||
___
|
||||
|
||||
### reducer
|
||||
|
||||
• **get reducer**(): *function*
|
||||
|
||||
A Redux reducer generated using the computed initial state and
|
||||
mutations.
|
||||
|
||||
**Returns:** *function*
|
||||
|
||||
▸ (`state`: S | undefined, `action`: [Action](../globals.md#action)): *S*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`state` | S | undefined |
|
||||
`action` | [Action](../globals.md#action) |
|
||||
|
||||
___
|
||||
|
||||
### selectors
|
||||
|
||||
• **get selectors**(): *[DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C›*
|
||||
|
||||
A dictionary of the updux's selectors. Subduxes'
|
||||
selectors are included as well (with the mapping to the
|
||||
sub-state already taken care of you).
|
||||
|
||||
**Returns:** *[DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C›*
|
||||
|
||||
___
|
||||
|
||||
### subduxUpreducer
|
||||
|
||||
• **get subduxUpreducer**(): *function*
|
||||
|
||||
Returns the upreducer made of the merge of all sudbuxes reducers, without
|
||||
the local mutations. Useful, for example, for sink mutations.
|
||||
|
||||
**`example`**
|
||||
|
||||
```
|
||||
import todo from './todo'; // updux for a single todo
|
||||
import Updux from 'updux';
|
||||
import u from 'updeep';
|
||||
|
||||
const todos = new Updux({ initial: [], subduxes: { '*': todo } });
|
||||
todos.addMutation(
|
||||
todo.actions.done,
|
||||
({todo_id},action) => u.map( u.if( u.is('id',todo_id) ), todos.subduxUpreducer(action) )
|
||||
true
|
||||
);
|
||||
```
|
||||
|
||||
**Returns:** *function*
|
||||
|
||||
▸ (`action`: [Action](../globals.md#action)): *function*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`action` | [Action](../globals.md#action) |
|
||||
|
||||
▸ (`state`: S): *S*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`state` | S |
|
||||
|
||||
___
|
||||
|
||||
### upreducer
|
||||
|
||||
• **get upreducer**(): *[Upreducer](../globals.md#upreducer)‹S›*
|
||||
|
||||
**Returns:** *[Upreducer](../globals.md#upreducer)‹S›*
|
||||
|
||||
## Methods
|
||||
|
||||
### addAction
|
||||
|
||||
▸ **addAction**(`theaction`: string, `transform?`: any): *ActionCreator‹string, any›*
|
||||
|
||||
Adds an action to the updux. It can take an already defined action
|
||||
creator, or any arguments that can be passed to `actionCreator`.
|
||||
|
||||
**`example`**
|
||||
```
|
||||
const action = updux.addAction( name, ...creatorArgs );
|
||||
const action = updux.addAction( otherActionCreator );
|
||||
```
|
||||
|
||||
**`example`**
|
||||
```
|
||||
import {actionCreator, Updux} from 'updux';
|
||||
|
||||
const updux = new Updux();
|
||||
|
||||
const foo = updux.addAction('foo');
|
||||
const bar = updux.addAction( 'bar', (x) => ({stuff: x+1}) );
|
||||
|
||||
const baz = actionCreator( 'baz' );
|
||||
|
||||
foo({ a: 1}); // => { type: 'foo', payload: { a: 1 } }
|
||||
bar(2); // => { type: 'bar', payload: { stuff: 3 } }
|
||||
baz(); // => { type: 'baz', payload: undefined }
|
||||
```
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`theaction` | string |
|
||||
`transform?` | any |
|
||||
|
||||
**Returns:** *ActionCreator‹string, any›*
|
||||
|
||||
▸ **addAction**(`theaction`: string | ActionCreator‹any›, `transform?`: undefined): *ActionCreator‹string, any›*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`theaction` | string | ActionCreator‹any› |
|
||||
`transform?` | undefined |
|
||||
|
||||
**Returns:** *ActionCreator‹string, any›*
|
||||
|
||||
___
|
||||
|
||||
### addEffect
|
||||
|
||||
▸ **addEffect**<**AC**>(`creator`: AC, `middleware`: [UpduxMiddleware](../globals.md#upduxmiddleware)‹AggDuxState‹S, C›, [DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C›, ReturnType‹AC››, `isGenerator?`: undefined | false | true): *any*
|
||||
|
||||
**Type parameters:**
|
||||
|
||||
▪ **AC**: *ActionCreator*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`creator` | AC |
|
||||
`middleware` | [UpduxMiddleware](../globals.md#upduxmiddleware)‹AggDuxState‹S, C›, [DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C›, ReturnType‹AC›› |
|
||||
`isGenerator?` | undefined | false | true |
|
||||
|
||||
**Returns:** *any*
|
||||
|
||||
▸ **addEffect**(`creator`: string, `middleware`: [UpduxMiddleware](../globals.md#upduxmiddleware)‹AggDuxState‹S, C›, [DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C››, `isGenerator?`: undefined | false | true): *any*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`creator` | string |
|
||||
`middleware` | [UpduxMiddleware](../globals.md#upduxmiddleware)‹AggDuxState‹S, C›, [DuxSelectors](../globals.md#duxselectors)‹AggDuxState‹S, C›, X, C›› |
|
||||
`isGenerator?` | undefined | false | true |
|
||||
|
||||
**Returns:** *any*
|
||||
|
||||
___
|
||||
|
||||
### addMutation
|
||||
|
||||
▸ **addMutation**<**A**>(`creator`: A, `mutation`: [Mutation](../globals.md#mutation)‹S, ActionType‹A››, `isSink?`: undefined | false | true): *any*
|
||||
|
||||
Adds a mutation and its associated action to the updux.
|
||||
|
||||
**`remarks`**
|
||||
|
||||
If a local mutation was already associated to the action,
|
||||
it will be replaced by the new one.
|
||||
|
||||
**`example`**
|
||||
|
||||
```js
|
||||
updux.addMutation(
|
||||
action('ADD', payload<int>() ),
|
||||
inc => state => state + in
|
||||
);
|
||||
```
|
||||
|
||||
**Type parameters:**
|
||||
|
||||
▪ **A**: *ActionCreator*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type | Description |
|
||||
------ | ------ | ------ |
|
||||
`creator` | A | - |
|
||||
`mutation` | [Mutation](../globals.md#mutation)‹S, ActionType‹A›› | - |
|
||||
`isSink?` | undefined | false | true | If `true`, disables the subduxes mutations for this action. To conditionally run the subduxes mutations, check out [subduxUpreducer](updux.md#subduxupreducer). Defaults to `false`. |
|
||||
|
||||
**Returns:** *any*
|
||||
|
||||
▸ **addMutation**<**A**>(`creator`: string, `mutation`: [Mutation](../globals.md#mutation)‹S, any›, `isSink?`: undefined | false | true): *any*
|
||||
|
||||
**Type parameters:**
|
||||
|
||||
▪ **A**: *ActionCreator*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`creator` | string |
|
||||
`mutation` | [Mutation](../globals.md#mutation)‹S, any› |
|
||||
`isSink?` | undefined | false | true |
|
||||
|
||||
**Returns:** *any*
|
||||
|
||||
___
|
||||
|
||||
### addSelector
|
||||
|
||||
▸ **addSelector**(`name`: string, `selector`: [Selector](../globals.md#selector)): *void*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`name` | string |
|
||||
`selector` | [Selector](../globals.md#selector) |
|
||||
|
||||
**Returns:** *void*
|
|
@ -1,980 +0,0 @@
|
|||
[updux - v1.2.0](README.md) › [Globals](globals.md)
|
||||
|
||||
# updux - v1.2.0
|
||||
|
||||
## Index
|
||||
|
||||
### Classes
|
||||
|
||||
* [Updux](classes/updux.md)
|
||||
|
||||
### Type aliases
|
||||
|
||||
* [Action](globals.md#action)
|
||||
* [ActionPair](globals.md#actionpair)
|
||||
* [ActionPayloadGenerator](globals.md#actionpayloadgenerator)
|
||||
* [ActionsOf](globals.md#actionsof)
|
||||
* [CoduxesOf](globals.md#coduxesof)
|
||||
* [Dictionary](globals.md#dictionary)
|
||||
* [Dux](globals.md#dux)
|
||||
* [DuxActions](globals.md#duxactions)
|
||||
* [DuxActionsCoduxes](globals.md#duxactionscoduxes)
|
||||
* [DuxActionsSubduxes](globals.md#duxactionssubduxes)
|
||||
* [DuxSelectors](globals.md#duxselectors)
|
||||
* [DuxState](globals.md#duxstate)
|
||||
* [DuxStateCoduxes](globals.md#duxstatecoduxes)
|
||||
* [DuxStateGlobSub](globals.md#duxstateglobsub)
|
||||
* [DuxStateSubduxes](globals.md#duxstatesubduxes)
|
||||
* [Effect](globals.md#effect)
|
||||
* [GenericActions](globals.md#genericactions)
|
||||
* [ItemsOf](globals.md#itemsof)
|
||||
* [LocalDuxState](globals.md#localduxstate)
|
||||
* [MaybePayload](globals.md#maybepayload)
|
||||
* [MaybeReturnType](globals.md#maybereturntype)
|
||||
* [Merge](globals.md#merge)
|
||||
* [Mutation](globals.md#mutation)
|
||||
* [MutationEntry](globals.md#mutationentry)
|
||||
* [MwGen](globals.md#mwgen)
|
||||
* [Next](globals.md#next)
|
||||
* [RebaseSelector](globals.md#rebaseselector)
|
||||
* [Selector](globals.md#selector)
|
||||
* [SelectorsOf](globals.md#selectorsof)
|
||||
* [StateOf](globals.md#stateof)
|
||||
* [StoreWithDispatchActions](globals.md#storewithdispatchactions)
|
||||
* [SubMutations](globals.md#submutations)
|
||||
* [Submws](globals.md#submws)
|
||||
* [UnionToIntersection](globals.md#uniontointersection)
|
||||
* [UpduxActions](globals.md#upduxactions)
|
||||
* [UpduxConfig](globals.md#upduxconfig)
|
||||
* [UpduxLocalActions](globals.md#upduxlocalactions)
|
||||
* [UpduxMiddleware](globals.md#upduxmiddleware)
|
||||
* [Upreducer](globals.md#upreducer)
|
||||
|
||||
### Variables
|
||||
|
||||
* [subEffects](globals.md#const-subeffects)
|
||||
* [updux](globals.md#const-updux)
|
||||
|
||||
### Functions
|
||||
|
||||
* [MiddlewareFor](globals.md#const-middlewarefor)
|
||||
* [buildActions](globals.md#buildactions)
|
||||
* [buildCreateStore](globals.md#buildcreatestore)
|
||||
* [buildInitial](globals.md#buildinitial)
|
||||
* [buildMiddleware](globals.md#buildmiddleware)
|
||||
* [buildMutations](globals.md#buildmutations)
|
||||
* [buildSelectors](globals.md#buildselectors)
|
||||
* [buildUpreducer](globals.md#buildupreducer)
|
||||
* [coduxes](globals.md#const-coduxes)
|
||||
* [composeMutations](globals.md#const-composemutations)
|
||||
* [composeMw](globals.md#const-composemw)
|
||||
* [dux](globals.md#const-dux)
|
||||
* [effectToMw](globals.md#const-effecttomw)
|
||||
* [sliceMw](globals.md#slicemw)
|
||||
* [subMiddleware](globals.md#const-submiddleware)
|
||||
* [subSelectors](globals.md#subselectors)
|
||||
|
||||
## Type aliases
|
||||
|
||||
### Action
|
||||
|
||||
Ƭ **Action**: *object & [MaybePayload](globals.md#maybepayload)‹P›*
|
||||
|
||||
___
|
||||
|
||||
### ActionPair
|
||||
|
||||
Ƭ **ActionPair**: *[string, ActionCreator]*
|
||||
|
||||
___
|
||||
|
||||
### ActionPayloadGenerator
|
||||
|
||||
Ƭ **ActionPayloadGenerator**: *function*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
▸ (...`args`: any[]): *any*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`...args` | any[] |
|
||||
|
||||
___
|
||||
|
||||
### ActionsOf
|
||||
|
||||
Ƭ **ActionsOf**: *U extends Updux ? U["actions"] : object*
|
||||
|
||||
___
|
||||
|
||||
### CoduxesOf
|
||||
|
||||
Ƭ **CoduxesOf**: *U extends Updux<any, any, any, infer S> ? S : []*
|
||||
|
||||
___
|
||||
|
||||
### Dictionary
|
||||
|
||||
Ƭ **Dictionary**: *object*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
* \[ **key**: *string*\]: T
|
||||
|
||||
___
|
||||
|
||||
### Dux
|
||||
|
||||
Ƭ **Dux**: *object*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
* **actions**: *A*
|
||||
|
||||
* **coduxes**: *[Dux](globals.md#dux)[]*
|
||||
|
||||
* **initial**: *AggDuxState‹S, C›*
|
||||
|
||||
* **subduxes**: *[Dictionary](globals.md#dictionary)‹[Dux](globals.md#dux)›*
|
||||
|
||||
___
|
||||
|
||||
### DuxActions
|
||||
|
||||
Ƭ **DuxActions**:
|
||||
|
||||
___
|
||||
|
||||
### DuxActionsCoduxes
|
||||
|
||||
Ƭ **DuxActionsCoduxes**: *C extends Array<infer I> ? UnionToIntersection<ActionsOf<I>> : object*
|
||||
|
||||
___
|
||||
|
||||
### DuxActionsSubduxes
|
||||
|
||||
Ƭ **DuxActionsSubduxes**: *C extends object ? ActionsOf<C[keyof C]> : unknown*
|
||||
|
||||
___
|
||||
|
||||
### DuxSelectors
|
||||
|
||||
Ƭ **DuxSelectors**: *unknown extends X ? object : X*
|
||||
|
||||
___
|
||||
|
||||
### DuxState
|
||||
|
||||
Ƭ **DuxState**: *D extends object ? S : unknown*
|
||||
|
||||
___
|
||||
|
||||
### DuxStateCoduxes
|
||||
|
||||
Ƭ **DuxStateCoduxes**: *C extends Array<infer U> ? UnionToIntersection<StateOf<U>> : unknown*
|
||||
|
||||
___
|
||||
|
||||
### DuxStateGlobSub
|
||||
|
||||
Ƭ **DuxStateGlobSub**: *S extends object ? StateOf<I> : unknown*
|
||||
|
||||
___
|
||||
|
||||
### DuxStateSubduxes
|
||||
|
||||
Ƭ **DuxStateSubduxes**: *C extends object ? object : C extends object ? object : unknown*
|
||||
|
||||
___
|
||||
|
||||
### Effect
|
||||
|
||||
Ƭ **Effect**: *[string, [UpduxMiddleware](globals.md#upduxmiddleware) | [MwGen](globals.md#mwgen), undefined | false | true]*
|
||||
|
||||
___
|
||||
|
||||
### GenericActions
|
||||
|
||||
Ƭ **GenericActions**: *[Dictionary](globals.md#dictionary)‹ActionCreator‹string, function››*
|
||||
|
||||
___
|
||||
|
||||
### ItemsOf
|
||||
|
||||
Ƭ **ItemsOf**: *C extends object ? C[keyof C] : unknown*
|
||||
|
||||
___
|
||||
|
||||
### LocalDuxState
|
||||
|
||||
Ƭ **LocalDuxState**: *S extends never[] ? unknown[] : S*
|
||||
|
||||
___
|
||||
|
||||
### MaybePayload
|
||||
|
||||
Ƭ **MaybePayload**: *P extends object | string | boolean | number ? object : object*
|
||||
|
||||
___
|
||||
|
||||
### MaybeReturnType
|
||||
|
||||
Ƭ **MaybeReturnType**: *X extends function ? ReturnType<X> : unknown*
|
||||
|
||||
___
|
||||
|
||||
### Merge
|
||||
|
||||
Ƭ **Merge**: *[UnionToIntersection](globals.md#uniontointersection)‹T[keyof T]›*
|
||||
|
||||
___
|
||||
|
||||
### Mutation
|
||||
|
||||
Ƭ **Mutation**: *function*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
▸ (`payload`: A["payload"], `action`: A): *function*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`payload` | A["payload"] |
|
||||
`action` | A |
|
||||
|
||||
▸ (`state`: S): *S*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`state` | S |
|
||||
|
||||
___
|
||||
|
||||
### MutationEntry
|
||||
|
||||
Ƭ **MutationEntry**: *[ActionCreator | string, [Mutation](globals.md#mutation)‹any, [Action](globals.md#action)‹string, any››, undefined | false | true]*
|
||||
|
||||
___
|
||||
|
||||
### MwGen
|
||||
|
||||
Ƭ **MwGen**: *function*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
▸ (): *[UpduxMiddleware](globals.md#upduxmiddleware)*
|
||||
|
||||
___
|
||||
|
||||
### Next
|
||||
|
||||
Ƭ **Next**: *function*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
▸ (`action`: [Action](globals.md#action)): *any*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`action` | [Action](globals.md#action) |
|
||||
|
||||
___
|
||||
|
||||
### RebaseSelector
|
||||
|
||||
Ƭ **RebaseSelector**: *object*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
___
|
||||
|
||||
### Selector
|
||||
|
||||
Ƭ **Selector**: *function*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
▸ (`state`: S): *unknown*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`state` | S |
|
||||
|
||||
___
|
||||
|
||||
### SelectorsOf
|
||||
|
||||
Ƭ **SelectorsOf**: *C extends object ? S : unknown*
|
||||
|
||||
___
|
||||
|
||||
### StateOf
|
||||
|
||||
Ƭ **StateOf**: *D extends object ? I : unknown*
|
||||
|
||||
___
|
||||
|
||||
### StoreWithDispatchActions
|
||||
|
||||
Ƭ **StoreWithDispatchActions**: *Store‹S› & object*
|
||||
|
||||
___
|
||||
|
||||
### SubMutations
|
||||
|
||||
Ƭ **SubMutations**: *object*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
* \[ **slice**: *string*\]: [Dictionary](globals.md#dictionary)‹[Mutation](globals.md#mutation)›
|
||||
|
||||
___
|
||||
|
||||
### Submws
|
||||
|
||||
Ƭ **Submws**: *[Dictionary](globals.md#dictionary)‹[UpduxMiddleware](globals.md#upduxmiddleware)›*
|
||||
|
||||
___
|
||||
|
||||
### UnionToIntersection
|
||||
|
||||
Ƭ **UnionToIntersection**: *U extends any ? function : never extends function ? I : never*
|
||||
|
||||
___
|
||||
|
||||
### UpduxActions
|
||||
|
||||
Ƭ **UpduxActions**: *U extends Updux ? UnionToIntersection<UpduxLocalActions<U> | ActionsOf<CoduxesOf<U>[keyof CoduxesOf<U>]>> : object*
|
||||
|
||||
___
|
||||
|
||||
### UpduxConfig
|
||||
|
||||
Ƭ **UpduxConfig**: *Partial‹object›*
|
||||
|
||||
Configuration object given to Updux's constructor.
|
||||
|
||||
#### arguments
|
||||
|
||||
##### initial
|
||||
|
||||
Default initial state of the reducer. If applicable, is merged with
|
||||
the subduxes initial states, with the parent having precedence.
|
||||
|
||||
If not provided, defaults to an empty object.
|
||||
|
||||
##### actions
|
||||
|
||||
[Actions](/concepts/Actions) used by the updux.
|
||||
|
||||
```js
|
||||
import { dux } from 'updux';
|
||||
import { action, payload } from 'ts-action';
|
||||
|
||||
const bar = action('BAR', payload<int>());
|
||||
const foo = action('FOO');
|
||||
|
||||
const myDux = dux({
|
||||
actions: {
|
||||
bar
|
||||
},
|
||||
mutations: [
|
||||
[ foo, () => state => state ]
|
||||
]
|
||||
});
|
||||
|
||||
myDux.actions.foo({ x: 1, y: 2 }); // => { type: foo, x:1, y:2 }
|
||||
myDux.actions.bar(2); // => { type: bar, payload: 2 }
|
||||
```
|
||||
|
||||
New actions used directly in mutations and effects will be added to the
|
||||
dux actions -- that is, they will be accessible via `dux.actions` -- but will
|
||||
not appear as part of its Typescript type.
|
||||
|
||||
##### selectors
|
||||
|
||||
Dictionary of selectors for the current updux. The updux also
|
||||
inherit its subduxes' selectors.
|
||||
|
||||
The selectors are available via the class' getter.
|
||||
|
||||
##### mutations
|
||||
|
||||
mutations: [
|
||||
[ action, mutation, isSink ],
|
||||
...
|
||||
]
|
||||
|
||||
or
|
||||
|
||||
mutations: {
|
||||
action: mutation,
|
||||
...
|
||||
}
|
||||
|
||||
List of mutations for assign to the dux. If you want Typescript goodness, you
|
||||
probably want to use `addMutation()` instead.
|
||||
|
||||
In its generic array-of-array form,
|
||||
each mutation tuple contains: the action, the mutation,
|
||||
and boolean indicating if this is a sink mutation.
|
||||
|
||||
The action can be an action creator function or a string. If it's a string, it's considered to be the
|
||||
action type and a generic `action( actionName, payload() )` creator will be
|
||||
generated for it. If an action is not already defined in the `actions`
|
||||
parameter, it'll be automatically added.
|
||||
|
||||
The pseudo-action type `*` can be used to match any action not explicitly matched by other mutations.
|
||||
|
||||
```js
|
||||
const todosUpdux = updux({
|
||||
mutations: {
|
||||
add: todo => state => [ ...state, todo ],
|
||||
done: done_id => u.map( u.if( ({id} => id === done_id), {done: true} ) ),
|
||||
'*' (payload,action) => state => {
|
||||
console.warn( "unexpected action ", action.type );
|
||||
return state;
|
||||
},
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
The signature of the mutations is `(payload,action) => state => newState`.
|
||||
It is designed to play well with `Updeep` (and [Immer](https://immerjs.github.io/immer/docs/introduction)). This way, instead of doing
|
||||
|
||||
```js
|
||||
mutation: {
|
||||
renameTodo: newName => state => { ...state, name: newName }
|
||||
}
|
||||
```
|
||||
|
||||
we can do
|
||||
|
||||
```js
|
||||
mutation: {
|
||||
renameTodo: newName => u({ name: newName })
|
||||
}
|
||||
```
|
||||
|
||||
The final argument is the optional boolean `isSink`. If it is true, it'll
|
||||
prevent subduxes' mutations on the same action. It defaults to `false`.
|
||||
|
||||
The object version of the argument can be used as a shortcut when all actions
|
||||
are strings. In that case, `isSink` is `false` for all mutations.
|
||||
|
||||
##### groomMutations
|
||||
|
||||
Function that can be provided to alter all local mutations of the updux
|
||||
(the mutations of subduxes are left untouched).
|
||||
|
||||
Can be used, for example, for Immer integration:
|
||||
|
||||
```js
|
||||
import Updux from 'updux';
|
||||
import { produce } from 'Immer';
|
||||
|
||||
const updux = new Updux({
|
||||
initial: { counter: 0 },
|
||||
groomMutations: mutation => (...args) => produce( mutation(...args) ),
|
||||
mutations: {
|
||||
add: (inc=1) => draft => draft.counter += inc
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Or perhaps for debugging:
|
||||
|
||||
```js
|
||||
import Updux from 'updux';
|
||||
|
||||
const updux = new Updux({
|
||||
initial: { counter: 0 },
|
||||
groomMutations: mutation => (...args) => state => {
|
||||
console.log( "got action ", args[1] );
|
||||
return mutation(...args)(state);
|
||||
}
|
||||
});
|
||||
```
|
||||
##### subduxes
|
||||
|
||||
Object mapping slices of the state to sub-upduxes. In addition to creating
|
||||
sub-reducers for those slices, it'll make the parend updux inherit all the
|
||||
actions and middleware from its subduxes.
|
||||
|
||||
For example, if in plain Redux you would do
|
||||
|
||||
```js
|
||||
import { combineReducers } from 'redux';
|
||||
import todosReducer from './todos';
|
||||
import statisticsReducer from './statistics';
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
todos: todosReducer,
|
||||
stats: statisticsReducer,
|
||||
});
|
||||
```
|
||||
|
||||
then with Updux you'd do
|
||||
|
||||
```js
|
||||
import { updux } from 'updux';
|
||||
import todos from './todos';
|
||||
import statistics from './statistics';
|
||||
|
||||
const rootUpdux = updux({
|
||||
subduxes: {
|
||||
todos,
|
||||
statistics
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
##### effects
|
||||
|
||||
Array of arrays or plain object defining asynchronous actions and side-effects triggered by actions.
|
||||
The effects themselves are Redux middleware, with the `dispatch`
|
||||
property of the first argument augmented with all the available actions.
|
||||
|
||||
```
|
||||
updux({
|
||||
effects: {
|
||||
fetch: ({dispatch}) => next => async (action) => {
|
||||
next(action);
|
||||
|
||||
let result = await fetch(action.payload.url).then( result => result.json() );
|
||||
dispatch.fetchSuccess(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
**`example`**
|
||||
|
||||
```
|
||||
import Updux from 'updux';
|
||||
import { actions, payload } from 'ts-action';
|
||||
import u from 'updeep';
|
||||
|
||||
const todoUpdux = new Updux({
|
||||
initial: {
|
||||
done: false,
|
||||
note: "",
|
||||
},
|
||||
actions: {
|
||||
finish: action('FINISH', payload()),
|
||||
edit: action('EDIT', payload()),
|
||||
},
|
||||
mutations: [
|
||||
[ edit, note => u({note}) ]
|
||||
],
|
||||
selectors: {
|
||||
getNote: state => state.note
|
||||
},
|
||||
groomMutations: mutation => transform(mutation),
|
||||
subduxes: {
|
||||
foo
|
||||
},
|
||||
effects: {
|
||||
finish: () => next => action => {
|
||||
console.log( "Woo! one more bites the dust" );
|
||||
}
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
___
|
||||
|
||||
### UpduxLocalActions
|
||||
|
||||
Ƭ **UpduxLocalActions**: *S extends Updux<any, null> ? object : S extends Updux<any, infer A> ? A : object*
|
||||
|
||||
___
|
||||
|
||||
### UpduxMiddleware
|
||||
|
||||
Ƭ **UpduxMiddleware**: *function*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
▸ (`api`: UpduxMiddlewareAPI‹S, X›): *function*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`api` | UpduxMiddlewareAPI‹S, X› |
|
||||
|
||||
▸ (`next`: Function): *function*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`next` | Function |
|
||||
|
||||
▸ (`action`: A): *any*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`action` | A |
|
||||
|
||||
___
|
||||
|
||||
### Upreducer
|
||||
|
||||
Ƭ **Upreducer**: *function*
|
||||
|
||||
#### Type declaration:
|
||||
|
||||
▸ (`action`: [Action](globals.md#action)): *function*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`action` | [Action](globals.md#action) |
|
||||
|
||||
▸ (`state`: S): *S*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`state` | S |
|
||||
|
||||
## Variables
|
||||
|
||||
### `Const` subEffects
|
||||
|
||||
• **subEffects**: *[Effect](globals.md#effect)* = [ '*', subMiddleware ] as any
|
||||
|
||||
___
|
||||
|
||||
### `Const` updux
|
||||
|
||||
• **updux**: *[Updux](classes/updux.md)‹unknown, null, unknown, object›* = new Updux({
|
||||
subduxes: {
|
||||
foo: dux({ initial: "banana" })
|
||||
}
|
||||
})
|
||||
|
||||
## Functions
|
||||
|
||||
### `Const` MiddlewareFor
|
||||
|
||||
▸ **MiddlewareFor**(`type`: any, `mw`: Middleware): *Middleware*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`type` | any |
|
||||
`mw` | Middleware |
|
||||
|
||||
**Returns:** *Middleware*
|
||||
|
||||
___
|
||||
|
||||
### buildActions
|
||||
|
||||
▸ **buildActions**(`actions`: [ActionPair](globals.md#actionpair)[]): *[Dictionary](globals.md#dictionary)‹ActionCreator‹string, function››*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type | Default |
|
||||
------ | ------ | ------ |
|
||||
`actions` | [ActionPair](globals.md#actionpair)[] | [] |
|
||||
|
||||
**Returns:** *[Dictionary](globals.md#dictionary)‹ActionCreator‹string, function››*
|
||||
|
||||
___
|
||||
|
||||
### buildCreateStore
|
||||
|
||||
▸ **buildCreateStore**<**S**, **A**>(`reducer`: Reducer‹S›, `middleware`: Middleware, `actions`: A): *function*
|
||||
|
||||
**Type parameters:**
|
||||
|
||||
▪ **S**
|
||||
|
||||
▪ **A**
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type | Default |
|
||||
------ | ------ | ------ |
|
||||
`reducer` | Reducer‹S› | - |
|
||||
`middleware` | Middleware | - |
|
||||
`actions` | A | {} as A |
|
||||
|
||||
**Returns:** *function*
|
||||
|
||||
▸ (`initial?`: S, `injectEnhancer?`: Function): *Store‹S› & object*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`initial?` | S |
|
||||
`injectEnhancer?` | Function |
|
||||
|
||||
___
|
||||
|
||||
### buildInitial
|
||||
|
||||
▸ **buildInitial**(`initial`: any, `coduxes`: any, `subduxes`: any): *any*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type | Default |
|
||||
------ | ------ | ------ |
|
||||
`initial` | any | - |
|
||||
`coduxes` | any | [] |
|
||||
`subduxes` | any | {} |
|
||||
|
||||
**Returns:** *any*
|
||||
|
||||
___
|
||||
|
||||
### buildMiddleware
|
||||
|
||||
▸ **buildMiddleware**<**S**>(`local`: [UpduxMiddleware](globals.md#upduxmiddleware)[], `co`: [UpduxMiddleware](globals.md#upduxmiddleware)[], `sub`: [Submws](globals.md#submws)): *[UpduxMiddleware](globals.md#upduxmiddleware)‹S›*
|
||||
|
||||
**Type parameters:**
|
||||
|
||||
▪ **S**
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type | Default |
|
||||
------ | ------ | ------ |
|
||||
`local` | [UpduxMiddleware](globals.md#upduxmiddleware)[] | [] |
|
||||
`co` | [UpduxMiddleware](globals.md#upduxmiddleware)[] | [] |
|
||||
`sub` | [Submws](globals.md#submws) | {} |
|
||||
|
||||
**Returns:** *[UpduxMiddleware](globals.md#upduxmiddleware)‹S›*
|
||||
|
||||
___
|
||||
|
||||
### buildMutations
|
||||
|
||||
▸ **buildMutations**(`mutations`: [Dictionary](globals.md#dictionary)‹[Mutation](globals.md#mutation) | [[Mutation](globals.md#mutation), boolean | undefined]›, `subduxes`: object, `coduxes`: [Upreducer](globals.md#upreducer)[]): *object*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type | Default |
|
||||
------ | ------ | ------ |
|
||||
`mutations` | [Dictionary](globals.md#dictionary)‹[Mutation](globals.md#mutation) | [[Mutation](globals.md#mutation), boolean | undefined]› | {} |
|
||||
`subduxes` | object | {} |
|
||||
`coduxes` | [Upreducer](globals.md#upreducer)[] | [] |
|
||||
|
||||
**Returns:** *object*
|
||||
|
||||
___
|
||||
|
||||
### buildSelectors
|
||||
|
||||
▸ **buildSelectors**(`localSelectors`: [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)›, `coduxes`: [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)›[], `subduxes`: [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)›): *object*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type | Default |
|
||||
------ | ------ | ------ |
|
||||
`localSelectors` | [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)› | {} |
|
||||
`coduxes` | [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)›[] | [] |
|
||||
`subduxes` | [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)› | {} |
|
||||
|
||||
**Returns:** *object*
|
||||
|
||||
___
|
||||
|
||||
### buildUpreducer
|
||||
|
||||
▸ **buildUpreducer**<**S**>(`initial`: S, `mutations`: [Dictionary](globals.md#dictionary)‹[Mutation](globals.md#mutation)‹S››): *[Upreducer](globals.md#upreducer)‹S›*
|
||||
|
||||
**Type parameters:**
|
||||
|
||||
▪ **S**
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`initial` | S |
|
||||
`mutations` | [Dictionary](globals.md#dictionary)‹[Mutation](globals.md#mutation)‹S›› |
|
||||
|
||||
**Returns:** *[Upreducer](globals.md#upreducer)‹S›*
|
||||
|
||||
___
|
||||
|
||||
### `Const` coduxes
|
||||
|
||||
▸ **coduxes**<**C**, **U**>(...`coduxes`: U): *object*
|
||||
|
||||
**Type parameters:**
|
||||
|
||||
▪ **C**: *[Dux](globals.md#dux)*
|
||||
|
||||
▪ **U**: *[C]*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`...coduxes` | U |
|
||||
|
||||
**Returns:** *object*
|
||||
|
||||
* **coduxes**: *U*
|
||||
|
||||
___
|
||||
|
||||
### `Const` composeMutations
|
||||
|
||||
▸ **composeMutations**(`mutations`: [Mutation](globals.md#mutation)[]): *function | (Anonymous function)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`mutations` | [Mutation](globals.md#mutation)[] |
|
||||
|
||||
**Returns:** *function | (Anonymous function)*
|
||||
|
||||
___
|
||||
|
||||
### `Const` composeMw
|
||||
|
||||
▸ **composeMw**(`mws`: [UpduxMiddleware](globals.md#upduxmiddleware)[]): *(Anonymous function)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`mws` | [UpduxMiddleware](globals.md#upduxmiddleware)[] |
|
||||
|
||||
**Returns:** *(Anonymous function)*
|
||||
|
||||
___
|
||||
|
||||
### `Const` dux
|
||||
|
||||
▸ **dux**<**S**, **A**, **X**, **C**>(`config`: C): *object*
|
||||
|
||||
**Type parameters:**
|
||||
|
||||
▪ **S**
|
||||
|
||||
▪ **A**
|
||||
|
||||
▪ **X**
|
||||
|
||||
▪ **C**: *[UpduxConfig](globals.md#upduxconfig)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`config` | C |
|
||||
|
||||
**Returns:** *object*
|
||||
|
||||
* **actions**: = this.actions
|
||||
|
||||
* **coduxes**: *object[]* = this.coduxes
|
||||
|
||||
* **createStore**(): *function*
|
||||
|
||||
* (`initial?`: S, `injectEnhancer?`: Function): *Store‹S› & object*
|
||||
|
||||
* **initial**: = this.initial
|
||||
|
||||
* **middleware**(): *function*
|
||||
|
||||
* (`api`: UpduxMiddlewareAPI‹S, X›): *function*
|
||||
|
||||
* (`next`: Function): *function*
|
||||
|
||||
* (`action`: A): *any*
|
||||
|
||||
* **mutations**(): *object*
|
||||
|
||||
* **reducer**(): *function*
|
||||
|
||||
* (`state`: S | undefined, `action`: [Action](globals.md#action)): *S*
|
||||
|
||||
* **selectors**: = this.selectors
|
||||
|
||||
* **subduxes**(): *object*
|
||||
|
||||
* **upreducer**(): *function*
|
||||
|
||||
* (`action`: [Action](globals.md#action)): *function*
|
||||
|
||||
* (`state`: S): *S*
|
||||
|
||||
___
|
||||
|
||||
### `Const` effectToMw
|
||||
|
||||
▸ **effectToMw**(`effect`: [Effect](globals.md#effect), `actions`: [Dictionary](globals.md#dictionary)‹ActionCreator›, `selectors`: [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)›): *subMiddleware | augmented*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`effect` | [Effect](globals.md#effect) |
|
||||
`actions` | [Dictionary](globals.md#dictionary)‹ActionCreator› |
|
||||
`selectors` | [Dictionary](globals.md#dictionary)‹[Selector](globals.md#selector)› |
|
||||
|
||||
**Returns:** *subMiddleware | augmented*
|
||||
|
||||
___
|
||||
|
||||
### sliceMw
|
||||
|
||||
▸ **sliceMw**(`slice`: string, `mw`: [UpduxMiddleware](globals.md#upduxmiddleware)): *[UpduxMiddleware](globals.md#upduxmiddleware)*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`slice` | string |
|
||||
`mw` | [UpduxMiddleware](globals.md#upduxmiddleware) |
|
||||
|
||||
**Returns:** *[UpduxMiddleware](globals.md#upduxmiddleware)*
|
||||
|
||||
___
|
||||
|
||||
### `Const` subMiddleware
|
||||
|
||||
▸ **subMiddleware**(): *(Anonymous function)*
|
||||
|
||||
**Returns:** *(Anonymous function)*
|
||||
|
||||
___
|
||||
|
||||
### subSelectors
|
||||
|
||||
▸ **subSelectors**(`__namedParameters`: [string, Function]): *[string, [Selector](globals.md#selector)][]*
|
||||
|
||||
**Parameters:**
|
||||
|
||||
Name | Type |
|
||||
------ | ------ |
|
||||
`__namedParameters` | [string, Function] |
|
||||
|
||||
**Returns:** *[string, [Selector](globals.md#selector)][]*
|
|
@ -1 +0,0 @@
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
import { expectType, expectError } from 'tsd';
|
||||
|
||||
import buildInitial from './src/buildInitial';
|
||||
|
||||
expectType<{}>(buildInitial());
|
||||
|
||||
type MyState = {
|
||||
foo: {
|
||||
bar: number
|
||||
},
|
||||
baz: string,
|
||||
}
|
||||
|
||||
expectType<MyState>(buildInitial<MyState>());
|
||||
|
||||
expectError( buildInitial<MyState>({ foo: { bar: "potato" } }) );
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
module.exports = {
|
||||
"roots": [
|
||||
"./src"
|
||||
],
|
||||
"transform": {
|
||||
"^.+\\.ts$": "ts-jest",
|
||||
"^.+\\.js$": "babel-jest",
|
||||
},
|
||||
}
|
|
@ -0,0 +1,293 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>JSDoc: Class: Updux</title>
|
||||
|
||||
<script src="scripts/prettify/prettify.js"> </script>
|
||||
<script src="scripts/prettify/lang-css.js"> </script>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
||||
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1 class="page-title">Class: Updux</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section>
|
||||
|
||||
<header>
|
||||
|
||||
<h2><span class="attribs"><span class="type-signature"></span></span>Updux<span class="signature">()</span><span class="type-signature"></span></h2>
|
||||
|
||||
|
||||
</header>
|
||||
|
||||
<article>
|
||||
<div class="container-overview">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="Updux"><span class="type-signature"></span>new Updux<span class="signature">()</span><span class="type-signature"></span></h4>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="Updux.js.html">Updux.js</a>, <a href="Updux.js.html#line24">line 24</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 class="subsection-title">Classes</h3>
|
||||
|
||||
<dl>
|
||||
<dt><a href="Updux.html">Updux</a></dt>
|
||||
<dd></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 class="subsection-title">Members</h3>
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="actions"><span class="type-signature"></span>actions<span class="type-signature"></span></h4>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="Updux.js.html">Updux.js</a>, <a href="Updux.js.html#line111">line 111</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="initial"><span class="type-signature"></span>initial<span class="type-signature"></span></h4>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="Updux.js.html">Updux.js</a>, <a href="Updux.js.html#line104">line 104</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Updux.html">Updux</a></li></ul>
|
||||
</nav>
|
||||
|
||||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Tue Oct 12 2021 10:16:59 GMT-0400 (Eastern Daylight Time)
|
||||
</footer>
|
||||
|
||||
<script> prettyPrint(); </script>
|
||||
<script src="scripts/linenumber.js"> </script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,368 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>JSDoc: Source: Updux.js</title>
|
||||
|
||||
<script src="scripts/prettify/prettify.js"> </script>
|
||||
<script src="scripts/prettify/lang-css.js"> </script>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
||||
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1 class="page-title">Source: Updux.js</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section>
|
||||
<article>
|
||||
<pre class="prettyprint source linenums"><code>/* TODO change * for leftovers to +, change subscriptions to reactions */
|
||||
import moize from 'moize';
|
||||
import u from '@yanick/updeep';
|
||||
import { createStore as reduxCreateStore, applyMiddleware } from 'redux';
|
||||
import { get, map, mapValues, merge, difference } from 'lodash-es';
|
||||
|
||||
import { buildInitial } from './buildInitial/index.js';
|
||||
import { buildActions } from './buildActions/index.js';
|
||||
import { buildSelectors } from './buildSelectors/index.js';
|
||||
import { action } from './actions.js';
|
||||
import { buildUpreducer } from './buildUpreducer.js';
|
||||
import {
|
||||
buildMiddleware,
|
||||
augmentMiddlewareApi,
|
||||
} from './buildMiddleware/index.js';
|
||||
|
||||
/**
|
||||
* @public
|
||||
* `Updux` is a way to minimize and simplify the boilerplate associated with the
|
||||
* creation of a `Redux` store. It takes a shorthand configuration
|
||||
* object, and generates the appropriate reducer, actions, middleware, etc.
|
||||
* In true `Redux`-like fashion, upduxes can be made of sub-upduxes (`subduxes` for short) for different slices of the root state.
|
||||
*/
|
||||
export class Updux {
|
||||
/** @type { unknown } */
|
||||
#initial = {};
|
||||
#subduxes = {};
|
||||
|
||||
/** @type Record<string,Function> */
|
||||
#actions = {};
|
||||
#selectors = {};
|
||||
#mutations = {};
|
||||
#effects = [];
|
||||
#subscriptions = [];
|
||||
#splatSelector = undefined;
|
||||
#splatReaction = undefined;
|
||||
|
||||
constructor(config) {
|
||||
this.#initial = config.initial ?? {};
|
||||
this.#subduxes = config.subduxes ?? {};
|
||||
|
||||
if (config.subduxes) {
|
||||
this.#subduxes = mapValues(config.subduxes, (sub) =>
|
||||
sub instanceof Updux ? sub : new Updux(sub)
|
||||
);
|
||||
}
|
||||
|
||||
if (config.actions) {
|
||||
for (const [type, actionArg] of Object.entries(config.actions)) {
|
||||
if (typeof actionArg === 'function' && actionArg.type) {
|
||||
this.#actions[type] = actionArg;
|
||||
} else {
|
||||
this.#actions[type] = action(type, actionArg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.#selectors = config.selectors ?? {};
|
||||
|
||||
this.#mutations = config.mutations ?? {};
|
||||
|
||||
this.#splatSelector = config.splatSelector;
|
||||
|
||||
Object.keys(this.#mutations)
|
||||
.filter((action) => action !== '*')
|
||||
.filter((action) => !this.actions.hasOwnProperty(action))
|
||||
.forEach((action) => {
|
||||
throw new Error(`action '${action}' is not defined`);
|
||||
});
|
||||
|
||||
if (config.effects) {
|
||||
this.#effects = Object.entries(config.effects);
|
||||
}
|
||||
|
||||
this.#subscriptions = config.subscriptions ?? [];
|
||||
|
||||
this.#splatReaction = config.splatReaction;
|
||||
}
|
||||
|
||||
#memoInitial = moize(buildInitial);
|
||||
#memoActions = moize(buildActions);
|
||||
#memoSelectors = moize(buildSelectors);
|
||||
#memoUpreducer = moize(buildUpreducer);
|
||||
#memoMiddleware = moize(buildMiddleware);
|
||||
|
||||
get subscriptions() {
|
||||
return this.#subscriptions;
|
||||
}
|
||||
|
||||
setSplatSelector(name, f) {
|
||||
this.#splatSelector = [name, f];
|
||||
}
|
||||
|
||||
get middleware() {
|
||||
return this.#memoMiddleware(
|
||||
this.#effects,
|
||||
this.actions,
|
||||
this.selectors,
|
||||
this.#subduxes
|
||||
);
|
||||
}
|
||||
|
||||
/** @return { import('./Updux').What } */
|
||||
get initial() {
|
||||
return this.#memoInitial(this.#initial, this.#subduxes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Record<string,Function>}
|
||||
*/
|
||||
get actions() {
|
||||
return this.#memoActions(this.#actions, this.#subduxes);
|
||||
}
|
||||
|
||||
get selectors() {
|
||||
return this.#memoSelectors(
|
||||
this.#selectors,
|
||||
this.#splatSelector,
|
||||
this.#subduxes
|
||||
);
|
||||
}
|
||||
|
||||
get upreducer() {
|
||||
return this.#memoUpreducer(
|
||||
this.initial,
|
||||
this.#mutations,
|
||||
this.#subduxes
|
||||
);
|
||||
}
|
||||
|
||||
get reducer() {
|
||||
return (state, action) => this.upreducer(action)(state);
|
||||
}
|
||||
|
||||
addSubscription(subscription) {
|
||||
this.#subscriptions = [...this.#subscriptions, subscription];
|
||||
}
|
||||
|
||||
addAction(type, payloadFunc) {
|
||||
const theAction = action(type, payloadFunc);
|
||||
|
||||
this.#actions = { ...this.#actions, [type]: theAction };
|
||||
|
||||
return theAction;
|
||||
}
|
||||
|
||||
addSelector(name, func) {
|
||||
this.#selectors = {
|
||||
...this.#selectors,
|
||||
[name]: func,
|
||||
};
|
||||
return func;
|
||||
}
|
||||
|
||||
addMutation(name, mutation) {
|
||||
if (typeof name === 'function') name = name.type;
|
||||
|
||||
this.#mutations = {
|
||||
...this.#mutations,
|
||||
[name]: mutation,
|
||||
};
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
addEffect(action, effect) {
|
||||
this.#effects = [...this.#effects, [action, effect]];
|
||||
}
|
||||
|
||||
splatSubscriber(store, inner, splatReaction) {
|
||||
const cache = {};
|
||||
|
||||
return () => (state, previous, unsub) => {
|
||||
const cacheKeys = Object.keys(cache);
|
||||
|
||||
const newKeys = difference(Object.keys(state), cacheKeys);
|
||||
|
||||
for (const slice of newKeys) {
|
||||
let localStore = {
|
||||
...store,
|
||||
getState: () => store.getState()[slice],
|
||||
};
|
||||
|
||||
cache[slice] = [];
|
||||
|
||||
if (typeof splatReaction === 'function') {
|
||||
localStore = {
|
||||
...localStore,
|
||||
...splatReaction(localStore, slice),
|
||||
};
|
||||
}
|
||||
|
||||
const { unsub, subscriber, subscriberRaw } =
|
||||
inner.subscribeAll(localStore);
|
||||
|
||||
cache[slice].push({ unsub, subscriber, subscriberRaw });
|
||||
subscriber();
|
||||
}
|
||||
|
||||
const deletedKeys = difference(cacheKeys, Object.keys(state));
|
||||
|
||||
for (const deleted of deletedKeys) {
|
||||
for (const inner of cache[deleted]) {
|
||||
inner.subscriber();
|
||||
inner.unsub();
|
||||
}
|
||||
delete cache[deleted];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
subscribeTo(store, subscription, setupArgs = []) {
|
||||
const localStore = augmentMiddlewareApi(
|
||||
{
|
||||
...store,
|
||||
subscribe: (subscriber) =>
|
||||
this.subscribeTo(store, () => subscriber),
|
||||
},
|
||||
this.actions,
|
||||
this.selectors
|
||||
);
|
||||
|
||||
const subscriber = subscription(localStore, ...setupArgs);
|
||||
|
||||
let previous;
|
||||
|
||||
const memoSub = () => {
|
||||
const state = store.getState();
|
||||
if (state === previous) return;
|
||||
let p = previous;
|
||||
previous = state;
|
||||
subscriber(state, p, unsub);
|
||||
};
|
||||
|
||||
let ret = store.subscribe(memoSub);
|
||||
const unsub = typeof ret === 'function' ? ret : ret.unsub;
|
||||
return {
|
||||
unsub,
|
||||
subscriber: memoSub,
|
||||
subscriberRaw: subscriber,
|
||||
};
|
||||
}
|
||||
|
||||
subscribeAll(store) {
|
||||
let results = this.#subscriptions.map((sub) =>
|
||||
this.subscribeTo(store, sub)
|
||||
);
|
||||
|
||||
for (const subdux in this.#subduxes) {
|
||||
if (subdux !== '*') {
|
||||
const localStore = {
|
||||
...store,
|
||||
getState: () => get(store.getState(), subdux),
|
||||
};
|
||||
results.push(this.#subduxes[subdux].subscribeAll(localStore));
|
||||
}
|
||||
}
|
||||
|
||||
if (this.#splatReaction) {
|
||||
results.push(
|
||||
this.subscribeTo(
|
||||
store,
|
||||
this.splatSubscriber(
|
||||
store,
|
||||
this.#subduxes['*'],
|
||||
this.#splatReaction
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
unsub: () => results.forEach(({ unsub }) => unsub()),
|
||||
subscriber: () => results.forEach(({ subscriber }) => subscriber()),
|
||||
subscriberRaw: (...args) =>
|
||||
results.forEach(({ subscriberRaw }) => subscriberRaw(...args)),
|
||||
};
|
||||
}
|
||||
|
||||
createStore(initial) {
|
||||
const store = reduxCreateStore(
|
||||
this.reducer,
|
||||
initial ?? this.initial,
|
||||
applyMiddleware(this.middleware)
|
||||
);
|
||||
|
||||
store.actions = this.actions;
|
||||
|
||||
store.selectors = this.selectors;
|
||||
|
||||
merge(
|
||||
store.getState,
|
||||
mapValues(this.selectors, (selector) => {
|
||||
return (...args) => {
|
||||
let result = selector(store.getState());
|
||||
|
||||
if (typeof result === 'function') return result(...args);
|
||||
|
||||
return result;
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
for (const action in this.actions) {
|
||||
store.dispatch[action] = (...args) => {
|
||||
return store.dispatch(this.actions[action](...args));
|
||||
};
|
||||
}
|
||||
|
||||
this.subscribeAll(store);
|
||||
|
||||
return store;
|
||||
}
|
||||
}
|
||||
|
||||
const x = new Updux();
|
||||
x.selectors;
|
||||
</code></pre>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Updux.html">Updux</a></li></ul>
|
||||
</nav>
|
||||
|
||||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Tue Oct 12 2021 10:16:59 GMT-0400 (Eastern Daylight Time)
|
||||
</footer>
|
||||
|
||||
<script> prettyPrint(); </script>
|
||||
<script src="scripts/linenumber.js"> </script>
|
||||
</body>
|
||||
</html>
|
After Width: | Height: | Size: 116 KiB |
After Width: | Height: | Size: 118 KiB |
After Width: | Height: | Size: 120 KiB |
After Width: | Height: | Size: 114 KiB |
After Width: | Height: | Size: 120 KiB |
After Width: | Height: | Size: 117 KiB |
|
@ -0,0 +1,65 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>JSDoc: Home</title>
|
||||
|
||||
<script src="scripts/prettify/prettify.js"> </script>
|
||||
<script src="scripts/prettify/lang-css.js"> </script>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
||||
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1 class="page-title">Home</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3> </h3>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Updux.html">Updux</a></li></ul>
|
||||
</nav>
|
||||
|
||||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Tue Oct 12 2021 10:16:59 GMT-0400 (Eastern Daylight Time)
|
||||
</footer>
|
||||
|
||||
<script> prettyPrint(); </script>
|
||||
<script src="scripts/linenumber.js"> </script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,25 @@
|
|||
/*global document */
|
||||
(() => {
|
||||
const source = document.getElementsByClassName('prettyprint source linenums');
|
||||
let i = 0;
|
||||
let lineNumber = 0;
|
||||
let lineId;
|
||||
let lines;
|
||||
let totalLines;
|
||||
let anchorHash;
|
||||
|
||||
if (source && source[0]) {
|
||||
anchorHash = document.location.hash.substring(1);
|
||||
lines = source[0].getElementsByTagName('li');
|
||||
totalLines = lines.length;
|
||||
|
||||
for (; i < totalLines; i++) {
|
||||
lineNumber++;
|
||||
lineId = `line${lineNumber}`;
|
||||
lines[i].id = lineId;
|
||||
if (lineId === anchorHash) {
|
||||
lines[i].className += ' selected';
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
|
@ -0,0 +1,202 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,2 @@
|
|||
PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n"]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com",
|
||||
/^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]);
|
|
@ -0,0 +1 @@
|
|||
declare var q: any;
|
|
@ -0,0 +1,28 @@
|
|||
var q=null;window.PR_SHOULD_USE_CONTINUATION=!0;
|
||||
(function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a=
|
||||
[],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c<i;++c){var j=f[c];if(/\\[bdsw]/i.test(j))a.push(j);else{var j=m(j),d;c+2<i&&"-"===f[c+1]?(d=m(f[c+2]),c+=2):d=j;b.push([j,d]);d<65||j>122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;c<b.length;++c)i=b[c],i[0]<=j[1]+1?j[1]=Math.max(j[1],i[1]):f.push(j=i);b=["["];o&&b.push("^");b.push.apply(b,a);for(c=0;c<
|
||||
f.length;++c)i=f[c],b.push(e(i[0])),i[1]>i[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c<b;++c){var j=f[c];j==="("?++i:"\\"===j.charAt(0)&&(j=+j.substring(1))&&j<=i&&(d[j]=-1)}for(c=1;c<d.length;++c)-1===d[c]&&(d[c]=++t);for(i=c=0;c<b;++c)j=f[c],j==="("?(++i,d[i]===void 0&&(f[c]="(?:")):"\\"===j.charAt(0)&&
|
||||
(j=+j.substring(1))&&j<=i&&(f[c]="\\"+d[i]);for(i=c=0;c<b;++c)"^"===f[c]&&"^"!==f[c+1]&&(f[c]="");if(a.ignoreCase&&s)for(c=0;c<b;++c)j=f[c],a=j.charAt(0),j.length>=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p<d;++p){var g=a[p];if(g.ignoreCase)l=!0;else if(/[a-z]/i.test(g.source.replace(/\\u[\da-f]{4}|\\x[\da-f]{2}|\\[^UXux]/gi,""))){s=!0;l=!1;break}}for(var r=
|
||||
{b:8,t:9,n:10,v:11,f:12,r:13},n=[],p=0,d=a.length;p<d;++p){g=a[p];if(g.global||g.multiline)throw Error(""+g);n.push("(?:"+y(g)+")")}return RegExp(n.join("|"),l?"gi":"g")}function M(a){function m(a){switch(a.nodeType){case 1:if(e.test(a.className))break;for(var g=a.firstChild;g;g=g.nextSibling)m(g);g=a.nodeName;if("BR"===g||"LI"===g)h[s]="\n",t[s<<1]=y++,t[s++<<1|1]=a;break;case 3:case 4:g=a.nodeValue,g.length&&(g=p?g.replace(/\r\n?/g,"\n"):g.replace(/[\t\n\r ]+/g," "),h[s]=g,t[s<<1]=y,y+=g.length,
|
||||
t[s++<<1|1]=a)}}var e=/(?:^|\s)nocode(?:\s|$)/,h=[],y=0,t=[],s=0,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=document.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);m(a);return{a:h.join("").replace(/\n$/,""),c:t}}function B(a,m,e,h){m&&(a={a:m,d:a},e(a),h.push.apply(h,a.e))}function x(a,m){function e(a){for(var l=a.d,p=[l,"pln"],d=0,g=a.a.match(y)||[],r={},n=0,z=g.length;n<z;++n){var f=g[n],b=r[f],o=void 0,c;if(typeof b===
|
||||
"string")c=!1;else{var i=h[f.charAt(0)];if(i)o=f.match(i[1]),b=i[0];else{for(c=0;c<t;++c)if(i=m[c],o=f.match(i[1])){b=i[0];break}o||(b="pln")}if((c=b.length>=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m),
|
||||
l=[],p={},d=0,g=e.length;d<g;++d){var r=e[d],n=r[3];if(n)for(var k=n.length;--k>=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/,
|
||||
q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/,
|
||||
q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g,
|
||||
"");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a),
|
||||
a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e}
|
||||
for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g<d.length;++g)e(d[g]);m===(m|0)&&d[0].setAttribute("value",
|
||||
m);var r=s.createElement("OL");r.className="linenums";for(var n=Math.max(0,m-1|0)||0,g=0,z=d.length;g<z;++g)l=d[g],l.className="L"+(g+n)%10,l.firstChild||l.appendChild(s.createTextNode("\xa0")),r.appendChild(l);a.appendChild(r)}function k(a,m){for(var e=m.length;--e>=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*</.test(m)?"default-markup":"default-code";return A[a]}function E(a){var m=
|
||||
a.g;try{var e=M(a.h),h=e.a;a.a=h;a.c=e.c;a.d=0;C(m,h)(a);var k=/\bMSIE\b/.test(navigator.userAgent),m=/\n/g,t=a.a,s=t.length,e=0,l=a.c,p=l.length,h=0,d=a.e,g=d.length,a=0;d[g]=s;var r,n;for(n=r=0;n<g;)d[n]!==d[n+2]?(d[r++]=d[n++],d[r++]=d[n++]):n+=2;g=r;for(n=r=0;n<g;){for(var z=d[n],f=d[n+1],b=n+2;b+2<=g&&d[b+1]===f;)b+=2;d[r++]=z;d[r++]=f;n=b}for(d.length=r;h<p;){var o=l[h+2]||s,c=d[a+2]||s,b=Math.min(o,c),i=l[h+1],j;if(i.nodeType!==1&&(j=t.substring(e,b))){k&&(j=j.replace(m,"\r"));i.nodeValue=
|
||||
j;var u=i.ownerDocument,v=u.createElement("SPAN");v.className=d[a+1];var x=i.parentNode;x.replaceChild(v,i);v.appendChild(i);e<o&&(l[h+1]=i=u.createTextNode(t.substring(b,o)),x.insertBefore(i,v.nextSibling))}e=b;e>=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"],
|
||||
"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"],
|
||||
H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"],
|
||||
J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+
|
||||
I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^<?]+/],["dec",/^<!\w[^>]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^<xmp\b[^>]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^<script\b[^>]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^<style\b[^>]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),
|
||||
["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css",
|
||||
/^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}),
|
||||
["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes",
|
||||
hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p<h.length&&l.now()<e;p++){var n=h[p],k=n.className;if(k.indexOf("prettyprint")>=0){var k=k.match(g),f,b;if(b=
|
||||
!k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p<h.length?setTimeout(m,
|
||||
250):a&&a()}for(var e=[document.getElementsByTagName("pre"),document.getElementsByTagName("code"),document.getElementsByTagName("xmp")],h=[],k=0;k<e.length;++k)for(var t=0,s=e[k].length;t<s;++t)h.push(e[k][t]);var e=q,l=Date;l.now||(l={now:function(){return+new Date}});var p=0,d,g=/\blang(?:uage)?-([\w.]+)(?!\S)/;m()};window.PR={createSimpleLexer:x,registerLangHandler:k,sourceDecorator:u,PR_ATTRIB_NAME:"atn",PR_ATTRIB_VALUE:"atv",PR_COMMENT:"com",PR_DECLARATION:"dec",PR_KEYWORD:"kwd",PR_LITERAL:"lit",
|
||||
PR_NOCODE:"nocode",PR_PLAIN:"pln",PR_PUNCTUATION:"pun",PR_SOURCE:"src",PR_STRING:"str",PR_TAG:"tag",PR_TYPE:"typ"}})();
|
|
@ -0,0 +1,358 @@
|
|||
@font-face {
|
||||
font-family: 'Open Sans';
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
src: url('../fonts/OpenSans-Regular-webfont.eot');
|
||||
src:
|
||||
local('Open Sans'),
|
||||
local('OpenSans'),
|
||||
url('../fonts/OpenSans-Regular-webfont.eot?#iefix') format('embedded-opentype'),
|
||||
url('../fonts/OpenSans-Regular-webfont.woff') format('woff'),
|
||||
url('../fonts/OpenSans-Regular-webfont.svg#open_sansregular') format('svg');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Open Sans Light';
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
src: url('../fonts/OpenSans-Light-webfont.eot');
|
||||
src:
|
||||
local('Open Sans Light'),
|
||||
local('OpenSans Light'),
|
||||
url('../fonts/OpenSans-Light-webfont.eot?#iefix') format('embedded-opentype'),
|
||||
url('../fonts/OpenSans-Light-webfont.woff') format('woff'),
|
||||
url('../fonts/OpenSans-Light-webfont.svg#open_sanslight') format('svg');
|
||||
}
|
||||
|
||||
html
|
||||
{
|
||||
overflow: auto;
|
||||
background-color: #fff;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
body
|
||||
{
|
||||
font-family: 'Open Sans', sans-serif;
|
||||
line-height: 1.5;
|
||||
color: #4d4e53;
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
a, a:visited, a:active {
|
||||
color: #0095dd;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
header
|
||||
{
|
||||
display: block;
|
||||
padding: 0px 4px;
|
||||
}
|
||||
|
||||
tt, code, kbd, samp {
|
||||
font-family: Consolas, Monaco, 'Andale Mono', monospace;
|
||||
}
|
||||
|
||||
.class-description {
|
||||
font-size: 130%;
|
||||
line-height: 140%;
|
||||
margin-bottom: 1em;
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
.class-description:empty {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#main {
|
||||
float: left;
|
||||
width: 70%;
|
||||
}
|
||||
|
||||
article dl {
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
|
||||
article img {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
section
|
||||
{
|
||||
display: block;
|
||||
background-color: #fff;
|
||||
padding: 12px 24px;
|
||||
border-bottom: 1px solid #ccc;
|
||||
margin-right: 30px;
|
||||
}
|
||||
|
||||
.variation {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.signature-attributes {
|
||||
font-size: 60%;
|
||||
color: #aaa;
|
||||
font-style: italic;
|
||||
font-weight: lighter;
|
||||
}
|
||||
|
||||
nav
|
||||
{
|
||||
display: block;
|
||||
float: right;
|
||||
margin-top: 28px;
|
||||
width: 30%;
|
||||
box-sizing: border-box;
|
||||
border-left: 1px solid #ccc;
|
||||
padding-left: 16px;
|
||||
}
|
||||
|
||||
nav ul {
|
||||
font-family: 'Lucida Grande', 'Lucida Sans Unicode', arial, sans-serif;
|
||||
font-size: 100%;
|
||||
line-height: 17px;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
list-style-type: none;
|
||||
}
|
||||
|
||||
nav ul a, nav ul a:visited, nav ul a:active {
|
||||
font-family: Consolas, Monaco, 'Andale Mono', monospace;
|
||||
line-height: 18px;
|
||||
color: #4D4E53;
|
||||
}
|
||||
|
||||
nav h3 {
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
nav li {
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
footer {
|
||||
display: block;
|
||||
padding: 6px;
|
||||
margin-top: 12px;
|
||||
font-style: italic;
|
||||
font-size: 90%;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4 {
|
||||
font-weight: 200;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
h1
|
||||
{
|
||||
font-family: 'Open Sans Light', sans-serif;
|
||||
font-size: 48px;
|
||||
letter-spacing: -2px;
|
||||
margin: 12px 24px 20px;
|
||||
}
|
||||
|
||||
h2, h3.subsection-title
|
||||
{
|
||||
font-size: 30px;
|
||||
font-weight: 700;
|
||||
letter-spacing: -1px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
h3
|
||||
{
|
||||
font-size: 24px;
|
||||
letter-spacing: -0.5px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
h4
|
||||
{
|
||||
font-size: 18px;
|
||||
letter-spacing: -0.33px;
|
||||
margin-bottom: 12px;
|
||||
color: #4d4e53;
|
||||
}
|
||||
|
||||
h5, .container-overview .subsection-title
|
||||
{
|
||||
font-size: 120%;
|
||||
font-weight: bold;
|
||||
letter-spacing: -0.01em;
|
||||
margin: 8px 0 3px 0;
|
||||
}
|
||||
|
||||
h6
|
||||
{
|
||||
font-size: 100%;
|
||||
letter-spacing: -0.01em;
|
||||
margin: 6px 0 3px 0;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
table
|
||||
{
|
||||
border-spacing: 0;
|
||||
border: 0;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
td, th
|
||||
{
|
||||
border: 1px solid #ddd;
|
||||
margin: 0px;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
padding: 4px 6px;
|
||||
display: table-cell;
|
||||
}
|
||||
|
||||
thead tr
|
||||
{
|
||||
background-color: #ddd;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
th { border-right: 1px solid #aaa; }
|
||||
tr > th:last-child { border-right: 1px solid #ddd; }
|
||||
|
||||
.ancestors, .attribs { color: #999; }
|
||||
.ancestors a, .attribs a
|
||||
{
|
||||
color: #999 !important;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.clear
|
||||
{
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.important
|
||||
{
|
||||
font-weight: bold;
|
||||
color: #950B02;
|
||||
}
|
||||
|
||||
.yes-def {
|
||||
text-indent: -1000px;
|
||||
}
|
||||
|
||||
.type-signature {
|
||||
color: #aaa;
|
||||
}
|
||||
|
||||
.name, .signature {
|
||||
font-family: Consolas, Monaco, 'Andale Mono', monospace;
|
||||
}
|
||||
|
||||
.details { margin-top: 14px; border-left: 2px solid #DDD; }
|
||||
.details dt { width: 120px; float: left; padding-left: 10px; padding-top: 6px; }
|
||||
.details dd { margin-left: 70px; }
|
||||
.details ul { margin: 0; }
|
||||
.details ul { list-style-type: none; }
|
||||
.details li { margin-left: 30px; padding-top: 6px; }
|
||||
.details pre.prettyprint { margin: 0 }
|
||||
.details .object-value { padding-top: 0; }
|
||||
|
||||
.description {
|
||||
margin-bottom: 1em;
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
.code-caption
|
||||
{
|
||||
font-style: italic;
|
||||
font-size: 107%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.source
|
||||
{
|
||||
border: 1px solid #ddd;
|
||||
width: 80%;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.prettyprint.source {
|
||||
width: inherit;
|
||||
}
|
||||
|
||||
.source code
|
||||
{
|
||||
font-size: 100%;
|
||||
line-height: 18px;
|
||||
display: block;
|
||||
padding: 4px 12px;
|
||||
margin: 0;
|
||||
background-color: #fff;
|
||||
color: #4D4E53;
|
||||
}
|
||||
|
||||
.prettyprint code span.line
|
||||
{
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.prettyprint.linenums
|
||||
{
|
||||
padding-left: 70px;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.prettyprint.linenums ol
|
||||
{
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
.prettyprint.linenums li
|
||||
{
|
||||
border-left: 3px #ddd solid;
|
||||
}
|
||||
|
||||
.prettyprint.linenums li.selected,
|
||||
.prettyprint.linenums li.selected *
|
||||
{
|
||||
background-color: lightyellow;
|
||||
}
|
||||
|
||||
.prettyprint.linenums li *
|
||||
{
|
||||
-webkit-user-select: text;
|
||||
-moz-user-select: text;
|
||||
-ms-user-select: text;
|
||||
user-select: text;
|
||||
}
|
||||
|
||||
.params .name, .props .name, .name code {
|
||||
color: #4D4E53;
|
||||
font-family: Consolas, Monaco, 'Andale Mono', monospace;
|
||||
font-size: 100%;
|
||||
}
|
||||
|
||||
.params td.description > p:first-child,
|
||||
.props td.description > p:first-child
|
||||
{
|
||||
margin-top: 0;
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
.params td.description > p:last-child,
|
||||
.props td.description > p:last-child
|
||||
{
|
||||
margin-bottom: 0;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.disabled {
|
||||
color: #454545;
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
/* JSDoc prettify.js theme */
|
||||
|
||||
/* plain text */
|
||||
.pln {
|
||||
color: #000000;
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* string content */
|
||||
.str {
|
||||
color: #006400;
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* a keyword */
|
||||
.kwd {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* a comment */
|
||||
.com {
|
||||
font-weight: normal;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* a type name */
|
||||
.typ {
|
||||
color: #000000;
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* a literal value */
|
||||
.lit {
|
||||
color: #006400;
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* punctuation */
|
||||
.pun {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* lisp open bracket */
|
||||
.opn {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* lisp close bracket */
|
||||
.clo {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* a markup tag name */
|
||||
.tag {
|
||||
color: #006400;
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* a markup attribute name */
|
||||
.atn {
|
||||
color: #006400;
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* a markup attribute value */
|
||||
.atv {
|
||||
color: #006400;
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* a declaration */
|
||||
.dec {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* a variable name */
|
||||
.var {
|
||||
color: #000000;
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* a function name */
|
||||
.fun {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* Specify class=linenums on a pre to get line numbering */
|
||||
ol.linenums {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
/* Tomorrow Theme */
|
||||
/* Original theme - https://github.com/chriskempson/tomorrow-theme */
|
||||
/* Pretty printing styles. Used with prettify.js. */
|
||||
/* SPAN elements with the classes below are added by prettyprint. */
|
||||
/* plain text */
|
||||
.pln {
|
||||
color: #4d4d4c; }
|
||||
|
||||
@media screen {
|
||||
/* string content */
|
||||
.str {
|
||||
color: #718c00; }
|
||||
|
||||
/* a keyword */
|
||||
.kwd {
|
||||
color: #8959a8; }
|
||||
|
||||
/* a comment */
|
||||
.com {
|
||||
color: #8e908c; }
|
||||
|
||||
/* a type name */
|
||||
.typ {
|
||||
color: #4271ae; }
|
||||
|
||||
/* a literal value */
|
||||
.lit {
|
||||
color: #f5871f; }
|
||||
|
||||
/* punctuation */
|
||||
.pun {
|
||||
color: #4d4d4c; }
|
||||
|
||||
/* lisp open bracket */
|
||||
.opn {
|
||||
color: #4d4d4c; }
|
||||
|
||||
/* lisp close bracket */
|
||||
.clo {
|
||||
color: #4d4d4c; }
|
||||
|
||||
/* a markup tag name */
|
||||
.tag {
|
||||
color: #c82829; }
|
||||
|
||||
/* a markup attribute name */
|
||||
.atn {
|
||||
color: #f5871f; }
|
||||
|
||||
/* a markup attribute value */
|
||||
.atv {
|
||||
color: #3e999f; }
|
||||
|
||||
/* a declaration */
|
||||
.dec {
|
||||
color: #f5871f; }
|
||||
|
||||
/* a variable name */
|
||||
.var {
|
||||
color: #c82829; }
|
||||
|
||||
/* a function name */
|
||||
.fun {
|
||||
color: #4271ae; } }
|
||||
/* Use higher contrast and text-weight for printable form. */
|
||||
@media print, projection {
|
||||
.str {
|
||||
color: #060; }
|
||||
|
||||
.kwd {
|
||||
color: #006;
|
||||
font-weight: bold; }
|
||||
|
||||
.com {
|
||||
color: #600;
|
||||
font-style: italic; }
|
||||
|
||||
.typ {
|
||||
color: #404;
|
||||
font-weight: bold; }
|
||||
|
||||
.lit {
|
||||
color: #044; }
|
||||
|
||||
.pun, .opn, .clo {
|
||||
color: #440; }
|
||||
|
||||
.tag {
|
||||
color: #006;
|
||||
font-weight: bold; }
|
||||
|
||||
.atn {
|
||||
color: #404; }
|
||||
|
||||
.atv {
|
||||
color: #060; } }
|
||||
/* Style */
|
||||
/*
|
||||
pre.prettyprint {
|
||||
background: white;
|
||||
font-family: Consolas, Monaco, 'Andale Mono', monospace;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
border: 1px solid #ccc;
|
||||
padding: 10px; }
|
||||
*/
|
||||
|
||||
/* Specify class=linenums on a pre to get line numbering */
|
||||
ol.linenums {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0; }
|
||||
|
||||
/* IE indents via margin-left */
|
||||
li.L0,
|
||||
li.L1,
|
||||
li.L2,
|
||||
li.L3,
|
||||
li.L4,
|
||||
li.L5,
|
||||
li.L6,
|
||||
li.L7,
|
||||
li.L8,
|
||||
li.L9 {
|
||||
/* */ }
|
||||
|
||||
/* Alternate shading for lines */
|
||||
li.L1,
|
||||
li.L3,
|
||||
li.L5,
|
||||
li.L7,
|
||||
li.L9 {
|
||||
/* */ }
|
65
package.json
|
@ -1,53 +1,20 @@
|
|||
{
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"lodash": "^4.17.15",
|
||||
"redux": "^4.0.5",
|
||||
"ts-action": "^11.0.0",
|
||||
"ts-node": "^8.6.2",
|
||||
"updeep": "^1.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.8.4",
|
||||
"@babel/core": "^7.8.7",
|
||||
"@babel/preset-env": "^7.8.7",
|
||||
"@types/jest": "^25.1.4",
|
||||
"@types/lodash": "^4.14.149",
|
||||
"@types/sinon": "^7.5.2",
|
||||
"@typescript-eslint/eslint-plugin": "^2.23.0",
|
||||
"@typescript-eslint/parser": "^2.23.0",
|
||||
"babel-jest": "^25.1.0",
|
||||
"docsify": "^4.11.2",
|
||||
"docsify-cli": "^4.4.0",
|
||||
"docsify-tools": "^1.0.20",
|
||||
"dtslint": "^3.3.0",
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-config-prettier": "^6.10.0",
|
||||
"eslint-plugin-import": "^2.20.1",
|
||||
"eslint-plugin-prettier": "^3.1.2",
|
||||
"glob": "^7.1.6",
|
||||
"jest": "^25.1.0",
|
||||
"promake": "^3.1.3",
|
||||
"sinon": "^9.0.1",
|
||||
"standard-version": "^8.0.0",
|
||||
"tap": "^14.10.6",
|
||||
"ts-jest": "^25.2.1",
|
||||
"tsd": "^0.11.0",
|
||||
"typedoc": "0.17.7",
|
||||
"typedoc-plugin-markdown": "^2.2.17",
|
||||
"typescript": "^3.8.3"
|
||||
"immer": "^9.0.15",
|
||||
"json-schema-shorthand": "^2.0.0",
|
||||
"redux": "^4.2.0",
|
||||
"remeda": "^1.0.1",
|
||||
"updeep": "^1.2.1"
|
||||
},
|
||||
"license": "MIT",
|
||||
"main": "dist/index.js",
|
||||
"main": "src/index.js",
|
||||
"name": "updux",
|
||||
"description": "Updeep-friendly Redux helper framework",
|
||||
"scripts": {
|
||||
"docsify:serve": "docsify serve docs",
|
||||
"build": "tsc",
|
||||
"test": "tap src/**test.ts",
|
||||
"lint": "prettier -c --",
|
||||
"lint:fix": "prettier --write --"
|
||||
"docsify:serve": "docsify serve docs"
|
||||
},
|
||||
"version": "2.1.0",
|
||||
"version": "4.0.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/yanick/updux.git"
|
||||
|
@ -61,10 +28,14 @@
|
|||
"url": "https://github.com/yanick/updux/issues"
|
||||
},
|
||||
"homepage": "https://github.com/yanick/updux#readme",
|
||||
"types": "./dist/index.d.ts",
|
||||
"prettier": {
|
||||
"tabWidth": 4,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "es5"
|
||||
"devDependencies": {
|
||||
"@vitest/browser": "^0.23.1",
|
||||
"@vitest/ui": "^0.23.1",
|
||||
"eslint": "^8.22.0",
|
||||
"eslint-plugin-no-only-tests": "^3.0.0",
|
||||
"eslint-plugin-todo-plz": "^1.2.1",
|
||||
"jsdoc-to-markdown": "^7.1.1",
|
||||
"prettier": "^2.7.1",
|
||||
"vitest": "0.23.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,315 @@
|
|||
import R from 'remeda';
|
||||
import u from 'updeep';
|
||||
import { createStore as reduxCreateStore, applyMiddleware } from 'redux';
|
||||
|
||||
import { buildSelectors } from './selectors.js';
|
||||
import { buildUpreducer } from './upreducer.js';
|
||||
import { buildMiddleware, augmentMiddlewareApi } from './middleware.js';
|
||||
import { action, isActionGen } from './actions.js';
|
||||
|
||||
/**
|
||||
* Updux configuration object
|
||||
* @typedef {Object} Updux config
|
||||
* @property {Object} actions - Actions to be made available to the updux.
|
||||
*/
|
||||
|
||||
export class Updux {
|
||||
#name = 'unknown';
|
||||
#localInitial = {};
|
||||
#subduxes = {};
|
||||
#actions;
|
||||
#mutations = {};
|
||||
#config = {};
|
||||
#selectors = {};
|
||||
#effects = [];
|
||||
#localReactions = [];
|
||||
#middlewareWrapper;
|
||||
#splatReactionMapper;
|
||||
|
||||
constructor(config = {}) {
|
||||
this.#config = config;
|
||||
|
||||
this.#name = config.name || 'unknown';
|
||||
|
||||
this.#splatReactionMapper = config.splatReactionMapper;
|
||||
|
||||
this.#middlewareWrapper = config.middlewareWrapper;
|
||||
|
||||
this.#localInitial = config.initial;
|
||||
this.#subduxes = config.subduxes ?? {};
|
||||
|
||||
this.#actions = R.mapValues(config.actions ?? {}, (arg, name) =>
|
||||
isActionGen(arg) ? arg : action(name, arg),
|
||||
);
|
||||
Object.entries(this.#subduxes).forEach(([slice, sub]) =>
|
||||
this.#addSubduxActions(slice, sub),
|
||||
);
|
||||
|
||||
Object.entries(config.mutations ?? {}).forEach((args) =>
|
||||
this.setMutation(...args),
|
||||
);
|
||||
|
||||
this.#selectors = buildSelectors(
|
||||
config.selectors,
|
||||
config.findSelectors,
|
||||
this.#subduxes,
|
||||
);
|
||||
|
||||
if (Array.isArray(config.effects)) {
|
||||
this.#effects = config.effects;
|
||||
} else if (R.isObject(config.effects)) {
|
||||
this.#effects = Object.entries(config.effects);
|
||||
}
|
||||
|
||||
this.#localReactions = config.reactions ?? [];
|
||||
}
|
||||
|
||||
get name() {
|
||||
return this.#name;
|
||||
}
|
||||
|
||||
#addSubduxActions(_slice, subdux) {
|
||||
if (!subdux.actions) return;
|
||||
// TODO action 'blah' defined multiple times: <where>
|
||||
Object.entries(subdux.actions).forEach(([action, gen]) => {
|
||||
if (this.#actions[action]) {
|
||||
if (this.#actions[action] === gen) return;
|
||||
throw new Error(`action '${action}' already defined`);
|
||||
}
|
||||
|
||||
this.#actions[action] = gen;
|
||||
});
|
||||
}
|
||||
|
||||
get selectors() {
|
||||
return this.#selectors;
|
||||
}
|
||||
|
||||
get actions() {
|
||||
return this.#actions;
|
||||
}
|
||||
|
||||
get initial() {
|
||||
if (Object.keys(this.#subduxes).length === 0)
|
||||
return this.#localInitial ?? {};
|
||||
|
||||
if (this.#subduxes['*']) {
|
||||
if (this.#localInitial) return this.#localInitial;
|
||||
return [];
|
||||
}
|
||||
|
||||
return Object.assign(
|
||||
{},
|
||||
this.#localInitial ?? {},
|
||||
R.mapValues(this.#subduxes, ({ initial }) => initial),
|
||||
);
|
||||
}
|
||||
|
||||
get reducer() {
|
||||
return (state, action) => this.upreducer(action)(state);
|
||||
}
|
||||
|
||||
get upreducer() {
|
||||
return buildUpreducer(this.#mutations, this.#subduxes);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string | Function} action - Action triggering the mutation. If
|
||||
* the action is a string, it has to have been previously declared for this
|
||||
* updux, but if it's a function generator, it'll be automatically added to the
|
||||
* updux if not already present (the idea being that making a typo on a string
|
||||
* is easy, but passing a wrong function very more unlikely).
|
||||
* @param {Function} mutation - Mutating function.
|
||||
* @param {bool} terminal - If true, subduxes' mutations won't be invoked on
|
||||
* the action.
|
||||
* @return {void}
|
||||
*/
|
||||
setMutation(action, mutation, terminal = false) {
|
||||
// TODO option strict: false to make it okay to auto-create
|
||||
// the actions as strings?
|
||||
if (action.type) {
|
||||
if (!this.#actions[action.type]) {
|
||||
this.#actions[action.type] = action;
|
||||
} else if (this.#actions[action.type] !== action) {
|
||||
throw new Error(
|
||||
`action '${action.type}' not defined for this updux or definition is different`,
|
||||
);
|
||||
}
|
||||
|
||||
action = action.type;
|
||||
}
|
||||
|
||||
if (!this.#actions[action] && action !== '*') {
|
||||
throw new Error(`action '${action}' is not defined`);
|
||||
}
|
||||
|
||||
if (terminal) {
|
||||
const originalMutation = mutation;
|
||||
mutation = (...args) => originalMutation(...args);
|
||||
mutation.terminal = true;
|
||||
}
|
||||
|
||||
this.#mutations[action] = mutation;
|
||||
}
|
||||
|
||||
get mutations() {
|
||||
return this.#mutations;
|
||||
}
|
||||
|
||||
get middleware() {
|
||||
return buildMiddleware(
|
||||
this.#effects,
|
||||
this.actions,
|
||||
this.selectors,
|
||||
this.#subduxes,
|
||||
this.#middlewareWrapper,
|
||||
);
|
||||
}
|
||||
|
||||
createStore(initial = undefined, enhancerGenerator = undefined) {
|
||||
const enhancer = (enhancerGenerator ?? applyMiddleware)(
|
||||
this.middleware,
|
||||
);
|
||||
|
||||
const store = reduxCreateStore(
|
||||
this.reducer,
|
||||
initial ?? this.initial,
|
||||
enhancer,
|
||||
);
|
||||
|
||||
store.actions = this.actions;
|
||||
|
||||
store.selectors = this.selectors;
|
||||
|
||||
Object.entries(this.selectors).forEach(([selector, fn]) => {
|
||||
store.getState[selector] = (...args) => {
|
||||
let result = fn(store.getState());
|
||||
|
||||
if (typeof result === 'function') return result(...args);
|
||||
|
||||
return result;
|
||||
};
|
||||
});
|
||||
|
||||
for (const action in this.actions) {
|
||||
store.dispatch[action] = (...args) => {
|
||||
return store.dispatch(this.actions[action](...args));
|
||||
};
|
||||
}
|
||||
|
||||
this.subscribeAll(store);
|
||||
|
||||
return store;
|
||||
}
|
||||
|
||||
addEffect(action, effect) {
|
||||
this.#effects = [...this.#effects, [action, effect]];
|
||||
}
|
||||
|
||||
addReaction(reaction) {
|
||||
this.#localReactions = [...this.#localReactions, reaction];
|
||||
}
|
||||
|
||||
augmentMiddlewareApi(api) {
|
||||
return augmentMiddlewareApi(api, this.actions, this.selectors);
|
||||
}
|
||||
|
||||
subscribeTo(store, subscription) {
|
||||
const localStore = this.augmentMiddlewareApi({
|
||||
...store,
|
||||
subscribe: (subscriber) => this.subscribeTo(store, subscriber), // TODO not sure
|
||||
});
|
||||
|
||||
const subscriber = subscription(localStore);
|
||||
|
||||
let previous;
|
||||
let unsub;
|
||||
|
||||
const memoSub = () => {
|
||||
const state = store.getState();
|
||||
if (state === previous) return;
|
||||
let p = previous;
|
||||
previous = state;
|
||||
subscriber(state, p, unsub);
|
||||
};
|
||||
|
||||
return store.subscribe(memoSub);
|
||||
}
|
||||
|
||||
createSplatReaction() {
|
||||
const subdux = this.#subduxes['*'];
|
||||
const mapper = this.#splatReactionMapper;
|
||||
|
||||
return (api) => {
|
||||
const cache = {};
|
||||
|
||||
return (state, previousState, unsubscribe) => {
|
||||
const gone = { ...cache };
|
||||
|
||||
// TODO assuming object here
|
||||
for (const key in state) {
|
||||
if (cache[key]) {
|
||||
delete gone[key];
|
||||
} else {
|
||||
const dux = new Updux({
|
||||
initial: null,
|
||||
actions: { update: null },
|
||||
mutations: {
|
||||
update: (payload) => () => payload,
|
||||
},
|
||||
});
|
||||
const store = dux.createStore();
|
||||
// TODO need to change the store to have the
|
||||
// subscribe pointing to the right slice?
|
||||
const context = {
|
||||
...(api.context ?? {}),
|
||||
[subdux.name]: key,
|
||||
};
|
||||
const unsub = subdux.subscribeAll({
|
||||
...store,
|
||||
context,
|
||||
});
|
||||
cache[key] = { store, unsub };
|
||||
}
|
||||
cache[key].store.dispatch.update(state[key]);
|
||||
}
|
||||
|
||||
for (const key in gone) {
|
||||
cache[key].store.dispatch.update(null);
|
||||
cache[key].unsub();
|
||||
delete cache[key];
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
subscribeSplatReaction(store) {
|
||||
return this.subscribeTo(store, this.createSplatReaction());
|
||||
}
|
||||
|
||||
subscribeAll(store) {
|
||||
let unsubs = this.#localReactions.map((sub) =>
|
||||
this.subscribeTo(store, sub),
|
||||
);
|
||||
|
||||
if (this.#splatReactionMapper) {
|
||||
unsubs.push(this.subscribeSplatReaction(store));
|
||||
}
|
||||
|
||||
unsubs.push(
|
||||
...Object.entries(this.#subduxes)
|
||||
.filter(([slice]) => slice !== '*')
|
||||
.map(([slice, subdux]) => {
|
||||
subdux.subscribeAll({
|
||||
...store,
|
||||
getState: () => store.getState()[slice],
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
return () => unsubs.forEach((u) => u());
|
||||
}
|
||||
}
|
||||
|
||||
export const dux = (config) => new Updux(config);
|
|
@ -1,121 +0,0 @@
|
|||
import Updux, { dux, coduxes } from '.';
|
||||
import { action, payload } from 'ts-action';
|
||||
import { test } from 'tap';
|
||||
import { expectAssignable } from 'tsd';
|
||||
import { DuxActionsCoduxes } from './types';
|
||||
|
||||
const foo_actions = {
|
||||
aaa: action('aaa', payload<number>()),
|
||||
};
|
||||
|
||||
const fooDux = dux({
|
||||
actions: foo_actions,
|
||||
});
|
||||
|
||||
const bar_actions = {
|
||||
bbb: action('bbb', (x: string) => ({ payload: '1' + x })),
|
||||
};
|
||||
|
||||
test('actions are present', t => {
|
||||
const barDux = dux({
|
||||
subduxes: { foo: fooDux },
|
||||
actions: bar_actions,
|
||||
});
|
||||
|
||||
const result = Object.keys(barDux.actions);
|
||||
result.sort();
|
||||
t.same(result, ['aaa', 'bbb']);
|
||||
t.end();
|
||||
});
|
||||
|
||||
const a = action('a');
|
||||
const b = action('b');
|
||||
|
||||
test('typing', t => {
|
||||
t.test('nothing at all', t => {
|
||||
const foo = new Updux();
|
||||
t.same(foo.actions, {});
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test('with two coduxes', t => {
|
||||
const myDux = new Updux({
|
||||
...coduxes(dux({ actions: { a } }), dux({ actions: { b } })),
|
||||
});
|
||||
|
||||
t.ok(myDux.actions.a);
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test('empty dux', t => {
|
||||
const empty = dux({});
|
||||
|
||||
expectAssignable<object>(empty.actions);
|
||||
|
||||
t.same(empty.actions, {}, 'no actions there');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test('coduxes actions', t => {
|
||||
const typeOf = <C>(x: C) => (x as any) as DuxActionsCoduxes<C>;
|
||||
|
||||
expectAssignable<{ a: any }>(typeOf([dux({ actions: { a } })]));
|
||||
expectAssignable<{}>(typeOf([dux({})]));
|
||||
|
||||
expectAssignable<{ a: any; b: any }>(
|
||||
typeOf([dux({ actions: { a } }), dux({ actions: { b } })])
|
||||
);
|
||||
|
||||
const co = coduxes(dux({ actions: { a } }), dux({})).coduxes;
|
||||
|
||||
expectAssignable<{ a: any }>(typeOf(co));
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test('with empty coduxes', t => {
|
||||
const emptyDux = dux({});
|
||||
|
||||
const myDux = dux({
|
||||
...coduxes(dux({ actions: { a } }), emptyDux),
|
||||
});
|
||||
|
||||
t.ok(myDux.actions.a);
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test('with three coduxes', t => {
|
||||
const emptyDux = new Updux();
|
||||
emptyDux.actions;
|
||||
|
||||
const dux = new Updux({
|
||||
coduxes: [
|
||||
emptyDux,
|
||||
new Updux({ actions: { a } }),
|
||||
new Updux({ actions: { b } }),
|
||||
],
|
||||
});
|
||||
|
||||
t.ok(dux.actions.b);
|
||||
t.end();
|
||||
});
|
||||
|
||||
t.test('with grandchild', t => {
|
||||
const dux = new Updux({
|
||||
subduxes: {
|
||||
bar: new Updux({
|
||||
subduxes: {
|
||||
baz: new Updux({
|
||||
actions: { a },
|
||||
}),
|
||||
},
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
t.ok(dux.actions.a);
|
||||
t.end();
|
||||
});
|
||||
t.end();
|
||||
});
|
|
@ -0,0 +1,26 @@
|
|||
export function isActionGen(action) {
|
||||
return typeof action === 'function' && action.type;
|
||||
}
|
||||
|
||||
export function action(type, payloadFunction, transformer) {
|
||||
let generator = function (...payloadArg) {
|
||||
const result = { type };
|
||||
|
||||
if (payloadFunction) {
|
||||
result.payload = payloadFunction(...payloadArg);
|
||||
} else {
|
||||
if (payloadArg[0] !== undefined) result.payload = payloadArg[0];
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
if (transformer) {
|
||||
const orig = generator;
|
||||
generator = (...args) => transformer(orig(...args), args);
|
||||
}
|
||||
|
||||
generator.type = type;
|
||||
|
||||
return generator;
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
import { test, expect } from 'vitest';
|
||||
|
||||
import { action } from './actions.js';
|
||||
|
||||
import { Updux } from './Updux.js';
|
||||
|
||||
test('basic action', () => {
|
||||
const foo = action('foo', (thing) => ({ thing }));
|
||||
|
||||
expect(foo('bar')).toEqual({
|
||||
type: 'foo',
|
||||
payload: {
|
||||
thing: 'bar',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('Updux config accepts actions', () => {
|
||||
const foo = new Updux({
|
||||
actions: {
|
||||
one: action('one', (x) => ({ x })),
|
||||
two: action('two', (x) => x),
|
||||
},
|
||||
});
|
||||
|
||||
expect(Object.keys(foo.actions)).toHaveLength(2);
|
||||
|
||||
expect(foo.actions.one).toBeTypeOf('function');
|
||||
expect(foo.actions.one('potato')).toEqual({
|
||||
type: 'one',
|
||||
payload: {
|
||||
x: 'potato',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('subduxes actions', () => {
|
||||
const foo = new Updux({
|
||||
actions: {
|
||||
foo: null,
|
||||
},
|
||||
subduxes: {
|
||||
beta: {
|
||||
actions: {
|
||||
bar: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(foo.actions).toHaveProperty('foo');
|
||||
expect(foo.actions).toHaveProperty('bar');
|
||||
});
|
||||
|
||||
test('throw if double action', () => {
|
||||
expect(
|
||||
() =>
|
||||
new Updux({
|
||||
actions: {
|
||||
foo: action('foo'),
|
||||
},
|
||||
subduxes: {
|
||||
beta: {
|
||||
actions: {
|
||||
foo: action('foo'),
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
).toThrow(/action 'foo' already defined/);
|
||||
});
|
||||
|
||||
test('action definition shortcut', () => {
|
||||
const foo = new Updux({
|
||||
actions: {
|
||||
foo: null,
|
||||
bar: (x) => ({ x }),
|
||||
},
|
||||
});
|
||||
|
||||
expect(foo.actions.foo('hello')).toEqual({ type: 'foo', payload: 'hello' });
|
||||
expect(foo.actions.bar('hello')).toEqual({
|
||||
type: 'bar',
|
||||
payload: { x: 'hello' },
|
||||
});
|
||||
});
|
|
@ -1,78 +0,0 @@
|
|||
import { action, payload } from 'ts-action';
|
||||
|
||||
import Updux, { dux } from '.';
|
||||
import { test } from 'tap';
|
||||
import { expectAssignable } from 'tsd';
|
||||
|
||||
const noopEffect = () => () => () => null;
|
||||
|
||||
test(
|
||||
'actions defined in effects and mutations, multi-level',
|
||||
{ autoend: true },
|
||||
t => {
|
||||
const bar = action('bar', (payload, meta) => ({ payload, meta }));
|
||||
const foo = action('foo', (limit: number) => ({
|
||||
payload: { limit },
|
||||
}));
|
||||
|
||||
const { actions }: any = dux({
|
||||
effects: [[foo, noopEffect] as any],
|
||||
mutations: [[bar, () => () => null]],
|
||||
subduxes: {
|
||||
mysub: dux({
|
||||
effects: { baz: noopEffect },
|
||||
mutations: { quux: () => () => null },
|
||||
actions: {
|
||||
foo,
|
||||
},
|
||||
}),
|
||||
myothersub: dux({
|
||||
effects: [[foo, noopEffect]],
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
const types = Object.keys(actions);
|
||||
types.sort();
|
||||
|
||||
t.match(types, ['bar', 'baz', 'foo', 'quux']);
|
||||
|
||||
t.match(actions.bar(), { type: 'bar' });
|
||||
t.match(actions.bar('xxx'), { type: 'bar', payload: 'xxx' });
|
||||
t.match(actions.bar(undefined, 'yyy'), {
|
||||
type: 'bar',
|
||||
payload: undefined,
|
||||
meta: 'yyy',
|
||||
});
|
||||
|
||||
t.same(actions.foo(12), { type: 'foo', payload: { limit: 12 } });
|
||||
}
|
||||
);
|
||||
|
||||
test('different calls to addAction', t => {
|
||||
const updux = new Updux<any,any>();
|
||||
|
||||
updux.addAction(action('foo', payload()));
|
||||
t.match(updux.actions.foo('yo'), {
|
||||
type: 'foo',
|
||||
payload: 'yo',
|
||||
});
|
||||
|
||||
updux.addAction('baz', x => ({ x }));
|
||||
t.match(updux.actions.baz(3), {
|
||||
type: 'baz',
|
||||
payload: { x: 3 },
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('types', t => {
|
||||
const {actions} = dux({ actions: {
|
||||
foo: action('foo')
|
||||
}});
|
||||
|
||||
expectAssignable<object>( actions );
|
||||
|
||||
t.end();
|
||||
});
|
|
@ -1,25 +0,0 @@
|
|||
import { action } from 'ts-action';
|
||||
import tap from 'tap';
|
||||
|
||||
import Updux from "./updux";
|
||||
|
||||
type MyState = {
|
||||
sum: number;
|
||||
};
|
||||
|
||||
tap.test("added mutation is present", t => {
|
||||
const updux = new Updux<MyState>({
|
||||
initial: { sum: 0 }
|
||||
});
|
||||
|
||||
const add = action("add", (n: number) => ({ payload: { n } }));
|
||||
|
||||
updux.addMutation(add, ({ n }) => ({ sum }) => ({ sum: sum + n }));
|
||||
|
||||
const store = updux.createStore();
|
||||
store.dispatch(add(3));
|
||||
|
||||
t.same(store.getState(), {sum: 3});
|
||||
|
||||
t.end();
|
||||
});
|
|
@ -1,22 +0,0 @@
|
|||
import fp from 'lodash/fp';
|
||||
import {
|
||||
ActionCreator
|
||||
} from 'ts-action';
|
||||
|
||||
import {
|
||||
Dictionary,
|
||||
} from '../types';
|
||||
|
||||
type ActionPair = [string, ActionCreator];
|
||||
|
||||
function buildActions(actions: ActionPair[] = []): Dictionary<ActionCreator<string,(...args: any) => {type: string} >>{
|
||||
// priority => generics => generic subs => craft subs => creators
|
||||
|
||||
const [crafted, generic] = fp.partition(([type, f]) => !f._genericAction)(
|
||||
fp.compact(actions)
|
||||
);
|
||||
|
||||
return fp.fromPairs([...generic, ...crafted]);
|
||||
}
|
||||
|
||||
export default buildActions;
|
|
@ -1,31 +0,0 @@
|
|||
import {
|
||||
createStore as reduxCreateStore,
|
||||
applyMiddleware,
|
||||
Middleware,
|
||||
Reducer,
|
||||
PreloadedState,
|
||||
Store,
|
||||
} from 'redux';
|
||||
|
||||
function buildCreateStore<S,A = {}>(
|
||||
reducer: Reducer<S>,
|
||||
middleware: Middleware,
|
||||
actions: A = {} as A,
|
||||
): (initial?: S, injectEnhancer?: Function) => Store<S> & { actions: A } {
|
||||
return function createStore(initial?: S, injectEnhancer?: Function ): Store<S> & { actions: A } {
|
||||
|
||||
let enhancer = injectEnhancer ? injectEnhancer(middleware) : applyMiddleware(middleware);
|
||||
|
||||
const store = reduxCreateStore(
|
||||
reducer,
|
||||
initial as PreloadedState<S>,
|
||||
enhancer
|
||||
);
|
||||
|
||||
(store as any).actions = actions;
|
||||
|
||||
return store as any;
|
||||
};
|
||||
}
|
||||
|
||||
export default buildCreateStore;
|
|
@ -1,28 +0,0 @@
|
|||
import tap from 'tap';
|
||||
import { expectType } from 'tsd';
|
||||
|
||||
import buildCreateStore from '.';
|
||||
import { action, ActionCreator } from 'ts-action';
|
||||
import {Reducer} from 'redux';
|
||||
|
||||
const foo = action('foo');
|
||||
const bar = action('bar');
|
||||
|
||||
type State = {
|
||||
x: number,
|
||||
y: string
|
||||
}
|
||||
|
||||
const store = buildCreateStore(
|
||||
((state: State|undefined) => state ?? {x: 1} ) as Reducer<State>,
|
||||
() => () => () => {return},
|
||||
{ foo, bar }
|
||||
)();
|
||||
|
||||
expectType<State>( store.getState() );
|
||||
expectType<number>( store.getState().x );
|
||||
|
||||
expectType<{ foo: ActionCreator }>( store.actions );
|
||||
|
||||
tap.pass();
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
import fp from 'lodash/fp';
|
||||
import u from 'updeep';
|
||||
|
||||
function buildInitial(initial: any, coduxes: any = [], subduxes: any = {}) {
|
||||
if (!fp.isPlainObject(initial)) return initial;
|
||||
|
||||
return fp.flow(
|
||||
[
|
||||
u(fp.omit(['*'], subduxes)),
|
||||
coduxes.map(i => u(i)),
|
||||
u(initial),
|
||||
].flat()
|
||||
)({});
|
||||
}
|
||||
|
||||
export default buildInitial;
|
|
@ -1,89 +0,0 @@
|
|||
import fp from 'lodash/fp';
|
||||
import { ActionCreator } from 'ts-action';
|
||||
|
||||
import { Middleware, MiddlewareAPI, Dispatch } from 'redux';
|
||||
import {
|
||||
Dictionary,
|
||||
Action,
|
||||
UpduxMiddleware,
|
||||
UpduxMiddlewareAPI,
|
||||
Selector,
|
||||
} from '../types';
|
||||
import Updux from '..';
|
||||
|
||||
const MiddlewareFor = (
|
||||
type: any,
|
||||
mw: Middleware
|
||||
): Middleware => api => next => action => {
|
||||
if (!type.includes('*') && action.type !== type) return next(action);
|
||||
|
||||
return mw(api)(next)(action);
|
||||
};
|
||||
|
||||
type Next = (action: Action) => any;
|
||||
|
||||
function sliceMw(slice: string, mw: UpduxMiddleware): UpduxMiddleware {
|
||||
return api => {
|
||||
const getSliceState = () => fp.get(slice, api.getState());
|
||||
return mw({ ...api, getState: getSliceState } as any);
|
||||
};
|
||||
}
|
||||
|
||||
type Submws = Dictionary<UpduxMiddleware>;
|
||||
|
||||
type MwGen = () => UpduxMiddleware;
|
||||
export type Effect = [string, UpduxMiddleware|MwGen, boolean? ];
|
||||
|
||||
export const subMiddleware = () => next => action => next(action);
|
||||
export const subEffects : Effect = [ '*', subMiddleware ] as any;
|
||||
|
||||
export const effectToMw = (
|
||||
effect: Effect,
|
||||
actions: Dictionary<ActionCreator>,
|
||||
selectors: Dictionary<Selector>,
|
||||
) => {
|
||||
let [type, mw, gen]: any = effect;
|
||||
|
||||
if ( mw === subMiddleware ) return subMiddleware;
|
||||
|
||||
if (gen) mw = mw();
|
||||
|
||||
const augmented = api => mw({ ...api, actions, selectors });
|
||||
|
||||
if (type === '*') return augmented;
|
||||
|
||||
return api => next => action => {
|
||||
if (action.type !== type) return next(action);
|
||||
|
||||
return augmented(api)(next)(action);
|
||||
};
|
||||
};
|
||||
|
||||
const composeMw = (mws: UpduxMiddleware[]) => (
|
||||
api: UpduxMiddlewareAPI<any>
|
||||
) => (original_next: Next) =>
|
||||
mws.reduceRight((next, mw) => mw(api)(next), original_next);
|
||||
|
||||
export function buildMiddleware<S = unknown>(
|
||||
local: UpduxMiddleware[] = [],
|
||||
co: UpduxMiddleware[] = [],
|
||||
sub: Submws = {}
|
||||
): UpduxMiddleware<S> {
|
||||
let inner = [
|
||||
...co,
|
||||
...Object.entries(sub).map(([slice, mw]) => sliceMw(slice, mw)),
|
||||
];
|
||||
|
||||
let found = false;
|
||||
let mws = local.flatMap(e => {
|
||||
if (e !== subMiddleware) return e;
|
||||
found = true;
|
||||
return inner;
|
||||
});
|
||||
|
||||
if (!found) mws = [...mws, ...inner];
|
||||
|
||||
return composeMw(mws) as UpduxMiddleware<S>;
|
||||
}
|
||||
|
||||
export default buildMiddleware;
|
|
@ -1,67 +0,0 @@
|
|||
import { buildMiddleware, subMiddleware } from '.';
|
||||
import tap from 'tap';
|
||||
import sinon from 'sinon';
|
||||
|
||||
const myMiddleware = (tag: string) => api => next => action => {
|
||||
next({
|
||||
...action,
|
||||
payload: [...action.payload, tag],
|
||||
});
|
||||
};
|
||||
|
||||
const local1 = myMiddleware('local1');
|
||||
const local2 = myMiddleware('local2');
|
||||
const co = myMiddleware('co');
|
||||
const sub = myMiddleware('sub');
|
||||
|
||||
tap.test('basic', t => {
|
||||
const next = sinon.fake();
|
||||
|
||||
const mw = buildMiddleware([local1, local2], [co], { sub });
|
||||
|
||||
mw({} as any)(next)({ type: 'foo', payload: [] });
|
||||
|
||||
t.match(next.firstCall.args, [
|
||||
{
|
||||
type: 'foo',
|
||||
payload: ['local1', 'local2', 'co', 'sub'],
|
||||
},
|
||||
]);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
tap.test('inner in the middle', t => {
|
||||
const next = sinon.fake();
|
||||
|
||||
const mw = buildMiddleware([local1, subMiddleware, local2], [co], {
|
||||
sub,
|
||||
});
|
||||
|
||||
mw({} as any)(next)({ type: 'foo', payload: [] });
|
||||
|
||||
t.match(next.firstCall.lastArg, {
|
||||
type: 'foo',
|
||||
payload: ['local1', 'co', 'sub', 'local2'],
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
tap.test('sub-mw get their store sliced', t => {
|
||||
const next = sinon.fake();
|
||||
|
||||
const sub = ({ getState }) => next => action => next(getState());
|
||||
|
||||
const mw = buildMiddleware([], [], { sub });
|
||||
|
||||
mw({
|
||||
getState() {
|
||||
return { foo: 1, sub: 2 };
|
||||
},
|
||||
} as any)(next)({ type: 'noop' });
|
||||
|
||||
t.same( next.firstCall.lastArg, 2 );
|
||||
|
||||
t.end();
|
||||
});
|
|
@ -1,57 +0,0 @@
|
|||
import fp from 'lodash/fp';
|
||||
import u from 'updeep';
|
||||
import {
|
||||
Mutation,
|
||||
Action,
|
||||
Dictionary,
|
||||
MutationEntry,
|
||||
Upreducer,
|
||||
} from '../types';
|
||||
import Updux from '..';
|
||||
|
||||
const composeMutations = (mutations: Mutation[]) => {
|
||||
if (mutations.length == 0) return () => state => state;
|
||||
|
||||
return mutations.reduce(
|
||||
(m1, m2) => (payload: any = null, action: Action) => state =>
|
||||
m2(payload, action)(m1(payload, action)(state))
|
||||
);
|
||||
};
|
||||
|
||||
type SubMutations = {
|
||||
[slice: string]: Dictionary<Mutation>;
|
||||
};
|
||||
|
||||
function buildMutations(
|
||||
mutations: Dictionary<Mutation | [Mutation, boolean | undefined]> = {},
|
||||
subduxes = {},
|
||||
coduxes: Upreducer[] = []
|
||||
) {
|
||||
const submuts = Object.entries(subduxes).map(
|
||||
([slice, upreducer]: [string, any]) =>
|
||||
<Mutation>(
|
||||
((payload, action: Action) =>
|
||||
(u.updateIn as any)(slice, upreducer(action)))
|
||||
)
|
||||
);
|
||||
|
||||
const comuts = coduxes.map(c => (payload, action: Action) => c(action));
|
||||
|
||||
const subreducer = composeMutations([...submuts, ...comuts]);
|
||||
|
||||
let merged = {};
|
||||
|
||||
Object.entries(mutations).forEach(([type, mutation]) => {
|
||||
const [m, sink] = Array.isArray(mutation)
|
||||
? mutation
|
||||
: [mutation, false];
|
||||
|
||||
merged[type] = sink ? m : composeMutations([subreducer, m]);
|
||||
});
|
||||
|
||||
if (!merged['*']) merged['*'] = subreducer;
|
||||
|
||||
return merged;
|
||||
}
|
||||
|
||||
export default buildMutations;
|
|
@ -1,27 +0,0 @@
|
|||
import fp from 'lodash/fp';
|
||||
import Updux from '..';
|
||||
import { Dictionary, Selector } from '../types';
|
||||
|
||||
function subSelectors([slice, selectors]: [string, Function]): [string, Selector][] {
|
||||
if (!selectors) return [];
|
||||
|
||||
return Object.entries(
|
||||
fp.mapValues(selector => (state: any) =>
|
||||
(selector as any)(state[slice])
|
||||
)(selectors as any)
|
||||
);
|
||||
}
|
||||
|
||||
export default function buildSelectors(
|
||||
localSelectors: Dictionary<Selector> = {},
|
||||
coduxes: Dictionary<Selector>[] = [],
|
||||
subduxes: Dictionary<Selector> = {}
|
||||
) {
|
||||
return Object.fromEntries(
|
||||
[
|
||||
Object.entries(subduxes).flatMap(subSelectors),
|
||||
Object.entries(coduxes),
|
||||
Object.entries(localSelectors),
|
||||
].flat()
|
||||
);
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
import u from 'updeep';
|
||||
import { mapValues } from 'lodash-es';
|
||||
|
||||
export function buildUpreducer(
|
||||
initial,
|
||||
mutations,
|
||||
subduxes = {},
|
||||
wrapper = undefined,
|
||||
) {
|
||||
const subReducers =
|
||||
Object.keys(subduxes).length > 0
|
||||
? mapValues(subduxes, ({ upreducer }) => upreducer)
|
||||
: null;
|
||||
|
||||
const upreducer = (action) => (state) => {
|
||||
if (!action?.type)
|
||||
throw new Error('upreducer called with a bad action');
|
||||
|
||||
let newState = state ?? initial;
|
||||
|
||||
if (subReducers) {
|
||||
if (subduxes['*']) {
|
||||
newState = u.updateIn(
|
||||
'*',
|
||||
subduxes['*'].upreducer(action),
|
||||
newState,
|
||||
);
|
||||
} else {
|
||||
const update = mapValues(subReducers, (upReducer) =>
|
||||
upReducer(action),
|
||||
);
|
||||
|
||||
newState = u(update, newState);
|
||||
}
|
||||
}
|
||||
|
||||
const a = mutations[action.type] || mutations['+'];
|
||||
|
||||
if (!a) return newState;
|
||||
|
||||
return a(action.payload, action)(newState);
|
||||
};
|
||||
|
||||
return wrapper ? wrapper(upreducer) : upreducer;
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
import fp from 'lodash/fp';
|
||||
|
||||
import { Dictionary, Mutation, Action, Upreducer } from '../types';
|
||||
|
||||
function buildUpreducer<S>(initial: S, mutations: Dictionary<Mutation<S>> ): Upreducer<S> {
|
||||
return (action :Action) => (state: S) => {
|
||||
if (state === undefined) state = initial;
|
||||
|
||||
const a =
|
||||
mutations[action.type] ||
|
||||
mutations['*'];
|
||||
|
||||
if(!a) return state;
|
||||
|
||||
return a(action.payload, action)(state);
|
||||
};
|
||||
}
|
||||
|
||||
export default buildUpreducer;
|
|
@ -1,36 +0,0 @@
|
|||
import Updux from '.';
|
||||
import { action } from 'ts-action';
|
||||
import { Effect } from './buildMiddleware';
|
||||
import tap from 'tap';
|
||||
import sinon from 'sinon';
|
||||
|
||||
const myEffect: Effect = [
|
||||
'*',
|
||||
() => next => action => next({ ...action, hello: true }),
|
||||
];
|
||||
|
||||
const codux = new Updux({
|
||||
actions: {
|
||||
foo: action('foo'),
|
||||
},
|
||||
effects: [myEffect],
|
||||
});
|
||||
|
||||
const dux = new Updux({
|
||||
coduxes: [codux],
|
||||
});
|
||||
|
||||
tap.test('actions', t => {
|
||||
t.ok(dux.actions.foo);
|
||||
t.end();
|
||||
});
|
||||
|
||||
tap.test('effects', t => {
|
||||
const next = sinon.fake();
|
||||
|
||||
dux.middleware({} as any)(next)({ type: 'foo' });
|
||||
|
||||
t.same(next.lastCall.lastArg, { type: 'foo', hello: true });
|
||||
|
||||
t.end();
|
||||
});
|