From b7da185a67a61c81702a29f108e45c1395877081 Mon Sep 17 00:00:00 2001 From: Robert Biggs Date: Sat, 26 Oct 2019 05:57:03 -0700 Subject: [PATCH] Improved types for effects.js and union.js. --- CHANGELOG.md | 10 ++++++++++ package-lock.json | 2 +- package.json | 2 +- src/effects.js | 16 ++++++++++++---- src/union.js | 5 +++++ 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb144e3..aecd33f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # composi/core Changelog +## 2.5.6 (October 26, 2019) + +### src/effects.js, src/union.js + +* Improved types for both effects.js and union.js. + +## 2.5.5 (October 25, 2019) + +* Removed `jsconfig.json` and replaced with `tsconfig.json`. The tsconfig has type check options. This removes need for NPM script test `checkjs` to use options, simplifying it to just `"checkjs": "tsc"`. + ## 2.5.4 (October 25, 2019) ### src/runtime.js diff --git a/package-lock.json b/package-lock.json index 6d3a143..769f628 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@composi/core", - "version": "2.5.5", + "version": "2.5.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 1f275eb..68fcabb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@composi/core", - "version": "2.5.5", + "version": "2.5.6", "description": "A JavaScript library for creating websites, PWAs and hybrid apps.", "main": "src/index.js", "module": "dist/composi-core.mjs", diff --git a/src/effects.js b/src/effects.js index 21bff3a..17cdcd3 100644 --- a/src/effects.js +++ b/src/effects.js @@ -1,7 +1,15 @@ +/** + * @typedef {import('./runtime').Send} Send + * @typedef {import('./runtime').Message} Message + * @typedef {Object} State + * @typedef {() => State} GetState + * @typedef {(getState: GetState, send: Send) => any} Effect + */ /** * Function to batch effects together. - * @param {...Function} effects - * @return {Function} Function + * @param {...Effect} effects + * @return {(getState: GetState, send: Send) => any} Function */ -export const batchEffects = (...effects) => (state, send) => - effects.map(effect => effect && effect(state, send)) +export const batchEffects = (...effects) => (getState, send) => + effects.map(effect => effect && effect(getState, send)) + diff --git a/src/union.js b/src/union.js index 636b8be..66bdbb5 100644 --- a/src/union.js +++ b/src/union.js @@ -34,9 +34,14 @@ function createUnion(types) { return { variants, match } } +/** + * @typedef {Object} MessageUnion + */ + /** * Create a union of types for matching up with functions. This is used to define actions for the `update` method of a runtime program. * @param {...string} types + * @returns {MessageUnion} MessagesUnion */ export function union(...types) { const { variants, match } = createUnion(types)