By default, the export package name for all APIs in this section is: @modern-js/runtime/model
.
If Reduck is integrated separately from Modern.js, the export package name is: @modern-js-reduck/react
.
Reduck can automatically generate Actions according to the type of State, for easy to modify State.
can use runtime.state.autoActions
close auto actions feature.
State type in string
、number
、boolean
、null
, generate setState
Action.
State type is Array, generate the following Actions:
push
: adds one or more elements to the end of the array.pop
: removes the last element from the array.shift
: removes the first element from the array.unshift
: adds one or more elements to the beginning of the array.
arr.unshift(element1, ..., elementN)
elementN
: the element or elements to add to the beginning of the array.filter
: filter element.concat
: concat array.splice
: modify the array by deleting or replacing existing elements or adding new elements in place, and return the modified array(Note that it is different from the native splice
return value).
splice(start[, deleteCount[, item1[, item2[, ...]]]])
start
: specifies the start position of the modification(counting from 0).deleteCount
: an integer representing the number of array elements to remove.item, item2, ...
: The elements to add to the array, starting at the start position. If not specified, splice
will only delete array elements.State type is PlainObject, base on the names contained in State, generate set${key}
(Camel-Case) Actions.