Add event emitter to datasource
Reviewed By: LukeDefeo Differential Revision: D51026560 fbshipit-source-id: 8348c6765633d7eecf0d1c80bc5bbd5af8130298
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3536ffe737
commit
da5856138d
@@ -11,6 +11,7 @@ import sortedIndexBy from 'lodash/sortedIndexBy';
|
|||||||
import sortedLastIndexBy from 'lodash/sortedLastIndexBy';
|
import sortedLastIndexBy from 'lodash/sortedLastIndexBy';
|
||||||
import property from 'lodash/property';
|
import property from 'lodash/property';
|
||||||
import lodashSort from 'lodash/sortBy';
|
import lodashSort from 'lodash/sortBy';
|
||||||
|
import EventEmitter from 'eventemitter3';
|
||||||
|
|
||||||
// If the dataSource becomes to large, after how many records will we start to drop items?
|
// If the dataSource becomes to large, after how many records will we start to drop items?
|
||||||
const dropFactor = 0.1;
|
const dropFactor = 0.1;
|
||||||
@@ -180,6 +181,8 @@ export class DataSource<T extends any, KeyType = never> {
|
|||||||
[viewId: string]: DataSourceView<T, KeyType>;
|
[viewId: string]: DataSourceView<T, KeyType>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public readonly outputEventEmitter = new EventEmitter();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
keyAttribute: keyof T | undefined,
|
keyAttribute: keyof T | undefined,
|
||||||
secondaryIndices: IndexDefinition<T>[] = [],
|
secondaryIndices: IndexDefinition<T>[] = [],
|
||||||
@@ -550,6 +553,7 @@ export class DataSource<T extends any, KeyType = never> {
|
|||||||
Object.entries(this.additionalViews).forEach(([, dataView]) => {
|
Object.entries(this.additionalViews).forEach(([, dataView]) => {
|
||||||
dataView.processEvent(event);
|
dataView.processEvent(event);
|
||||||
});
|
});
|
||||||
|
this.outputEventEmitter.emit(event.type, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
private storeSecondaryIndices(value: T) {
|
private storeSecondaryIndices(value: T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user