INNER CODE UNIT · JavaScript
_itemAdded
fullstackreact/react-native-firestack · lib/firestackModule.js:86
const _itemAdded = (snapshot, prevKey) => {
const state = this._getState(); // local state
const newItem = toObject(snapshot, state);
let list = state.items || [];
list.push(newItem)
list = list.sort(this._sortFn)
return this._handleUpdate(T.ITEM_ADDED, {items: list}, cb);
}
const _itemRemoved = (snapshot, prevKey) => {
const state = this._getState(); // local state
const itemKeys = state.items.map(i => i._key);
const itemIndex = itemKeys.indexOf(snapshot.key);
let newItems = [].concat(state.items);
newItems.splice(itemIndex, 1);
let list = newItems.sort(this._sortFn)
return this._handleUpdate(T.ITEM_REMOVED, {items: list}, cb);
}
const _itemChanged = (snapshot, prevKey) => {