@action-land/core 中文文档教程

发布于 5年前 浏览 11 更新于 3年前

@action-type/core

动作的核心库。

Index

Installation

npm i @action-land/core

Specification

  1. An Action consists of two properties viz. type and value.
  2. action.type is of type string or number.
  3. action.value is of type any. It could also be of type Action
  4. The object is an immutable and should never be updated.

Action Type

一个动作是一个包含两个属性的对象——typevalue

interface Action<T> {
  type: string
  value: T
}

API

action

有助于创建新的操作类型对象的实用程序。 该函数默认是柯里化的,并提供类型保证。

import {action} from '@action-land/core'

action('click', {x: 10, y: 20})

action('click')({x: 10, y: 20}) // curried version

isAction

检测对象是否为 Action 类型的实用程序函数。

import {isAction} from '@action-land/core'

isAction({}) // returns false
isAction(action('WWW', null)) // returns true

Nil

代表虚无的默认动作。

import {Nil} from '@action-land/core'

function logic(a: number) {
  if (a > 10) return action('greater', a - 10)
  if (a < 10) return action('lesser', 10 - a)
  return Nil
}

List

Action[] 列表创建 Action 的实用程序函数。

import {List} from '@action-land/core'

const list = List(action('A', 1), action('B', 2))

isList

检查操作是否为列表类型

import {isList} from '@action-land/core'

const list = List(action('A', 1), action('B', 2))

isList(list) //true

isNil

的实用函数 检查操作是否为 Nil 的实用函数

import {isNil, Nil} from '@action-land/core'

isNil(Nil) // true
isNil({type: '@@NIL', value: {}}) // true
isNil({type: 'click', value: {}}) // false

@action-type/core

Core library for action.

Index

Installation

npm i @action-land/core

Specification

  1. An Action consists of two properties viz. type and value.
  2. action.type is of type string or number.
  3. action.value is of type any. It could also be of type Action
  4. The object is an immutable and should never be updated.

Action Type

An action is an object which contains two properties — type and value.

interface Action<T> {
  type: string
  value: T
}

API

action

A utility that helps in creating a new object of action type. The function is curried by default and provides type guarantee.

import {action} from '@action-land/core'

action('click', {x: 10, y: 20})

action('click')({x: 10, y: 20}) // curried version

isAction

A utility function that detects if the object is of Action type.

import {isAction} from '@action-land/core'

isAction({}) // returns false
isAction(action('WWW', null)) // returns true

Nil

A default action that represents nothingness.

import {Nil} from '@action-land/core'

function logic(a: number) {
  if (a > 10) return action('greater', a - 10)
  if (a < 10) return action('lesser', 10 - a)
  return Nil
}

List

A utility function that creates an Action from a list of Action[].

import {List} from '@action-land/core'

const list = List(action('A', 1), action('B', 2))

isList

A utility function that checks if the action is of list type

import {isList} from '@action-land/core'

const list = List(action('A', 1), action('B', 2))

isList(list) //true

isNil

A utility function that checks if the action is of Nil

import {isNil, Nil} from '@action-land/core'

isNil(Nil) // true
isNil({type: '@@NIL', value: {}}) // true
isNil({type: 'click', value: {}}) // false
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文