XOrderedList
A useful tool to manage array of object.
Introduction
Sometimes it would be a headache to maintain and to manipulate an array of object. ListStore is just a Map
wrapper Object that enhances the original Map
object. It looks like a small "database" which will help you manage arrays in a rather comfortable way.
How to use it
install
npm install xorderedlist
example
const list = id: 1 name: 'one' console // 1 list list list list list list list list
APIs
Properties
Name | Type | default |
---|---|---|
data | Map | [] |
idAttr | String | 'id' |
values | Array | [] |
keys | Array | [] |
size | number | [] |
length | number | [] |
first | Object/undefined | undefined |
last | Object/undefined | undefined |
Methods
Name | argument | return | description |
---|---|---|---|
findOne | id: Any | Object | Same to Map.get. Query one result from list |
findList | idList: Array | Object | Query results |
insertOne | obj: Object | this | Insert data after the given id of the list |
unshift | arrOfObject: Array | this | Add data to the start of list |
push | arrOfObject: Array | this | Add data at the end of list |
update | arrOfObject: Array | this | Update the given data |
delete | idList: Array | this | Delete data by the given id list |
mutate | callback: Function, argument: Object | Array | change the data by your own method. Support one extra argument |
License
MIT