0.9.4 • Published 7 years ago

emce-child-list v0.9.4

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

Emce Child List

A mixin for Emce to create a list of Emces from an array in your model.

Installation

Install from npm:

npm install emce-child-list --save

or

yarn add emce-child-list

Creating Lists

If your model has an array of models you would like to create Emces for, use createList it will return an observable of ChildLists which will contain an Emce for each model in the array. Each time the array is updated you will get a new list of Emces, the model objects are tracked by the property specified on create. The same Emce will always represent the same model object. You do not have to handle disposing of the Emces yourself, that will be done for you. The Emces in the list will return a new value for the model in the array it represents, just as the Emces created by createChild.

Note: Due to the limitation of not being able to set a type of a keyof in typescript the createList method does not check that the types are correct and you can get a run time error if you have not selected a list. Make sure you have an empty array if there is nothing in the list.

The create list takes an executer for the Emces in the array, an id parameter; used to track the models, and then you select in the same way as in createChild.

  emce.createList(new ChildExecutor, 'id', 'children')
  .subscribe((list: ChildList<ExampleChild, ExampleAction, EmceChildList<ExampleChild, ExampleAction>) => {
    // handle list update
  })

If the model you are watching is removed the list observable will be completed and you will have to create a new one to watch the model again.

Problems

If you are using other middlewares you must cast the response from createList.

ChildList

A child list is a list of Emces. It is returned from the createList method.

The list is iterable, and you can get an item by using the get method with an id. The id is read on the property given when creating the list.

const child: EmceChildList<Example, ExampleAction> = childList.get(id)
0.9.4

7 years ago

0.9.3

7 years ago

0.9.2

7 years ago

0.9.1

7 years ago

0.9.0

7 years ago