The literal type of the data contained by the list instance.
Example:
This example will create a list of object that contains at start one name and to which a second name is append.
const myList<string>(['Fred'])
myList.add('Nicolas')
An array with the initial content of the list.
Add an element at the end of the list.
An observable on the contained data.
Example:
const s = new State<number>(0)
s.obs$.filter(v => v%2==0 ).subscribe(stateContent => console.dir(stateContent))
Retrieve the number of element in the list.
An Observable on the number of elements.
Property to retrieve a subject to be used to update the content.
Examples:
The following add a value to the content of a State that contain a list of number. Subscribers will receive updates. (see update for an example with more explanations)
const s = new State<number[]>([1])
s.obs$.subscribe(stateContent => console.dir(stateContent))
const append => newVal => stateContent => [...stateContent, newVal]
s.updater$s.next(append(2)); // see below the update syntax shortcut.
It is also possible to directly set the state instead of passing a function updating the state
const s = new State<number[]>([1])
s.obs$.subscribe(stateContent => console.dir(stateContent))
s.updater$s.next([3,4,5])
In some case it is not required have any initial value
const s = new State<number>() // no initial value
s.obs$.subscribe(stateContent => console.dir(stateContent)) // triggered with a 1 second delay
setTimeout(() => s.update(1), 1000) // delay the update
A subject for updating the content.
Remark: The returned observer is partial and will ignore error
and complete
messages.
Add an element at the end of the list.
The element to append to the list.
A cold observable containing the index of the added element in the list.
Retrieve the element value from the list according to its possition in the list.
A hot observable to the element.
Remove the last element of the list.
A cold observable containing the value of the removed element in the list (observable will return undefined if the list is empty).
Remove an element using its position in the list.
The position index of the element to remove.
Remove an element at the start of the list.
a cold observable on the removed element (observable returns undefined if the list is empty).
Add an element at the start of the list.
The element to prepend to the list.
nothing.
Method to be used to update the content.
Example 1:
The following add a value to the content of a State that contain a list of number. Subscribers will receive updates.
// Create a state with an initial value
const s = new State<number[]>([1])
// Subscribe to the state
s.obs$.subscribe(stateContent => console.dir(stateContent))
// transformation function that append a value at the end of an array and
// return the new array.
const append => newVal => stateContent => {return [...stateContent, newVal]}
// Append 2 at the end of the array contained in the state s.
// (Subscribers, like above will be triggered)
s.update(append(2))
Example 2:
The following set the content of a State that contain a list of number. Subscribers will receive updates.
// Create a state with an initial value
const s = new State<number[]>([1])
// Subscribe to the state
s.obs$.subscribe(stateContent => console.dir(stateContent))
// Set the new array contained in the state s.
// (Subscribers, like above will be triggered)
s.update([3,4])
Example 3:
The following exemple create a state without initial value. Later the content is set and latter it is updated
// Create a state with an initial value
const s = new State<number[]>()
// Subscribe to the state
s.obs$.subscribe(stateContent => console.dir(stateContent))
// transformation function that append a value at the end of an array and
// return the new array.
const append => newVal => stateContent => [...stateContent, newVal]
// Set an initial value
// Set the new array contained in the state s.
// (Subscribers, like above will be triggered)
s.update([1])
// Update the content by adding a value to the list
// Set the new array contained in the state s.
// (Subscribers, like above will be triggered)
s.update(append(2));
A transformation function that takes as argument the current data of the state and return the updated data.
nothing
Generated using TypeDoc
A generic list of literal.
The T type that describe the type of data in the list shall be a literal.
The list is indexed using a number like a normal list. If you need a list of object with a specialized function for creating an index in the object, you'd rather use ObjList instead.
The list inherit from the State object. It can be subscribed to using the obs$ attribute and other method or attribute can be used (like update method).