aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-11-24 02:35:18 +0800
committerGitHub <noreply@github.com>2017-11-24 02:35:18 +0800
commitf97074dc84b5c45b9c487ee27ca7ed671bb6fd71 (patch)
treeecbddf9d12c430fbe9f934d627c54b92bad05f1b /packages/0x.js/src
parentbd81124b5a1d7927f54848ead39297cc62ea2dbc (diff)
parentc858ff61f7ef8b1941f3f5832713b1d87d92a2af (diff)
downloaddexon-sol-tools-f97074dc84b5c45b9c487ee27ca7ed671bb6fd71.tar
dexon-sol-tools-f97074dc84b5c45b9c487ee27ca7ed671bb6fd71.tar.gz
dexon-sol-tools-f97074dc84b5c45b9c487ee27ca7ed671bb6fd71.tar.bz2
dexon-sol-tools-f97074dc84b5c45b9c487ee27ca7ed671bb6fd71.tar.lz
dexon-sol-tools-f97074dc84b5c45b9c487ee27ca7ed671bb6fd71.tar.xz
dexon-sol-tools-f97074dc84b5c45b9c487ee27ca7ed671bb6fd71.tar.zst
dexon-sol-tools-f97074dc84b5c45b9c487ee27ca7ed671bb6fd71.zip
Merge pull request #230 from 0xProject/feature/removeDuplicateEvents
Add an order state cache to filter out duplicate events
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r--packages/0x.js/src/order_watcher/order_state_watcher.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts
index fd7496699..44a41669d 100644
--- a/packages/0x.js/src/order_watcher/order_state_watcher.ts
+++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts
@@ -44,6 +44,10 @@ interface OrderByOrderHash {
[orderHash: string]: SignedOrder;
}
+interface OrderStateByOrderHash {
+ [orderHash: string]: OrderState;
+}
+
/**
* This class includes all the functionality related to watching a set of orders
* for potential changes in order validity/fillability. The orderWatcher notifies
@@ -51,6 +55,7 @@ interface OrderByOrderHash {
* the order should be deemed invalid.
*/
export class OrderStateWatcher {
+ private _orderStateByOrderHashCache: OrderStateByOrderHash = {};
private _orderByOrderHash: OrderByOrderHash = {};
private _dependentOrderHashes: DependentOrderHashes = {};
private _callbackIfExists?: OnOrderStateChangeCallback;
@@ -109,6 +114,7 @@ export class OrderStateWatcher {
return; // noop
}
delete this._orderByOrderHash[orderHash];
+ delete this._orderStateByOrderHashCache[orderHash];
const exchange = (this._orderFilledCancelledLazyStore as any).exchange as ExchangeWrapper;
const zrxTokenAddress = await exchange.getZRXTokenAddressAsync();
this.removeFromDependentOrderHashes(signedOrder.maker, zrxTokenAddress, orderHash);
@@ -239,6 +245,12 @@ export class OrderStateWatcher {
if (_.isUndefined(this._callbackIfExists)) {
break; // Unsubscribe was called
}
+ if (_.isEqual(orderState, this._orderStateByOrderHashCache[orderHash])) {
+ // Actual order state didn't change
+ continue;
+ } else {
+ this._orderStateByOrderHashCache[orderHash] = orderState;
+ }
this._callbackIfExists(orderState);
}
}