Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Commit

Permalink
Improved types for effects.js and union.js.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wobbabits committed Oct 26, 2019
1 parent 20211f8 commit b7da185
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
16 changes: 12 additions & 4 deletions src/effects.js
Original file line number Diff line number Diff line change
@@ -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))

5 changes: 5 additions & 0 deletions src/union.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b7da185

Please sign in to comment.