4.0.1 • Published 6 years ago

action-type v4.0.1

Weekly downloads
6
License
ISC
Repository
github
Last release
6 years ago

Action-Type Build Status

Type class specification for actions.

Index

Ecosystem

ProjectDescription
HoeAn action emitter library for the DOM.
Update Function TypesUtilities for doing more complex operations based on Action and some State
Match ActionSwitch-case for Actions
Action ComponentA library to create components with Action and State

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-type'

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-type'

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

Nil

A default action that represents nothingness.

import {Nil} from 'action-type'

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-type'

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-type'

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-type'

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

6 years ago

4.0.0

6 years ago

3.1.1

6 years ago

3.1.0

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.0.0

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago