Abstract
initialization items
parent item
import * as collection from '@biorate/collection';
class List extends collection.ObservableList<{ id: number }> {
protected get _keys() {
return [['id']];
}
}
const list = new List([{ id: 1 }, { id: 2 }, { id: 3 }]);
Rest
...args: any[]Rest
Callbacks storage
Key combinations storage
Current processing item alias, useful for dynamic class substitution in _Item getter
Unique items storage
Protected
_Object instantiation. The constructor from which the instance will be created must be passed here. If null is passed, the object that was passed will be added to the collection.
**null**
class List extends collection.List<{ id: number }> {
protected get _keys() {
return [['id']];
}
protected get _Item() {
return null;
}
}
const list = new List([{ id: 1 }, { id: 2 }]);
console.log(list.find(1)); // { id: 1 }
console.log(list.find(1)); // { id: 2 }
import * as collection from '@biorate/collection';
const { embed } = collection;
class Item extends collection.Item {
@embed(Item.Int) public id: number = null;
@embed(Item.String) public title: string = null;
}
class List extends collection.List<Item> {
protected get _keys() {
return [['id']];
}
protected get _Item() {
return Item;
}
}
const list = new List([{ id: 1, title: 'Cat' }, { id: 2, title: 'Dog' }]);
console.log(list.find(1)); // Item { id: 1, title: 'Cat' }
console.log(list.find(2)); // Item { id: 2, title: 'Dog' }
Protected
Abstract
_keysIndexes map. Designed to declare fields by which indexes will be built.
class List extends collection.List<{ a: number; b: number; c: number }> {
protected get _keys() {
return [
['a', 'b'],
['b', 'c'],
];
}
}
const list = new List([
{ a: 1, b: 1, c: 3 },
{ a: 2, b: 2, c: 2 },
{ a: 3, b: 1, c: 1 },
]);
console.log(list.get(1, 1)); // [ { a: 1, b: 1, c: 3 }, { a: 3, b: 1, c: 1 } ]
console.log(list.get(2, 2)); // [ { a: 2, b: 2, c: 2 } ]
Alias to current processed item, to private #processed property. Useful for dynamic class substitution in _Item getter
class Base extends collection.Item {
id: number = null;
type: string = null;
}
class One extends Base {}
class Two extends Base {}
class Three extends Base {}
const Types = { One, Two, Three }
class List extends collection.List<Base> {
protected get _keys() {
return [['id']];
}
protected get _Item() {
return Types[this.processed.type];
}
}
const list = new List([
{ id: 1, type: 'One' },
{ id: 2, type: 'Two' },
{ id: 3, type: 'Three' }
]);
console.log(list.find(1)); // One { id: 1, type: 'One' }
console.log(list.find(2)); // Two { id: 2, type: 'Two' }
console.log(list.find(3)); // Three { id: 3, type: 'Three' }
Protected
_setGetter alias for unique items storage (for internal usage)
Setter alias for unique items storage (for internal usage)
Alias to parent class
Unique collection items count
const list = new List([{ id: 1 }, { id: 2 }, { id: 3 }]);
console.log(list.size); // 3
Static
indexAlias for index-symbol, if used in _keys getter - enumerate and index items with sequence number.
import { List as Base } from '@biorate/collection';
class List extends Base<{ id: number }> {
protected get _keys() {
return [[Base.index]];
}
}
const list = new List([{ id: 3 }, { id: 2 }, { id: 1 }]);
console.log(list.find(0)); // { id: 3, [Symbol(Props.Index)]: 0 }
console.log(list.find(1)); // { id: 2, [Symbol(Props.Index)]: 1 }
console.log(list.find(2)); // { id: 1, [Symbol(Props.Index)]: 2 }
query params
return only first item?
Get all items by criteria
const list = new List([{ id: 1, a: 1 }, { id: 2, a: 1 }, { id: 3, a: 2 }]);
list.getBy({ a: 1 }); // [{ id: 1, a: 1 }, { id: 2, a: 1 }]
list.getBy({ id: 1, a: 1 }); // [{ id: 1, a: 1 }]
Rest
...args: any[]Rest
Subscribe to changes
const list = new List([{ id: 1 }, { id: 2 }, { id: 3 }]);
const callback = (data) => console.log(data);
list.subscribe(callback);
Rest
...args: any[]Rest
Unsubscribe from changes
list.unsubscribe(callback);
Generated using TypeDoc
Description
This class inherits from List and implements the mobx observer interface nested over all object properties
Features:
Example