@action-land/match 中文文档教程
@action-land/match
动作的开关盒。
Installation
npm i @action-land/match
Usage
公开一个 match()
函数——
- Accepts two arguments —
default
andspec
. default
is a function that accepts theaction
and can return anything.spec
is an object where key isaction.type
and value is a function.- On a successful match of
action.type
the corresponding function is called with theaction.value
.
import {action} from '@action-land/core'
import {match} from '@action-land/match'
const fn = match(i => i, {
inc: i => i + 1,
dec: i => i - 1
})
fn(action('inc', 10)) // returns 11
@action-land/match
A switch case for actions.
Installation
npm i @action-land/match
Usage
Exposes a single match()
function that —
- Accepts two arguments —
default
andspec
. default
is a function that accepts theaction
and can return anything.spec
is an object where key isaction.type
and value is a function.- On a successful match of
action.type
the corresponding function is called with theaction.value
.
import {action} from '@action-land/core'
import {match} from '@action-land/match'
const fn = match(i => i, {
inc: i => i + 1,
dec: i => i - 1
})
fn(action('inc', 10)) // returns 11