From 6b1b91274a398ef964e44a89fabdf32b2ef142c4 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 3 Oct 2019 15:27:20 -0400 Subject: [PATCH 1/2] feat: extend contract events to include tracking --- examples/react-example1/src/App.js | 2 +- src/subspace.js | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/react-example1/src/App.js b/examples/react-example1/src/App.js index a4415ad..a5cdd8f 100644 --- a/examples/react-example1/src/App.js +++ b/examples/react-example1/src/App.js @@ -23,7 +23,7 @@ class App extends React.Component { Product = await ProductContract.getInstance(); Product = subspace.contract(Product) - const rating$ = Product.trackEvent("Rating").map("rating").pipe(map(x => parseInt(x))); + const rating$ = Product.events.Rating.track().map("rating").pipe(map(x => parseInt(x))); window.Product = Product; window.web3 = web3; diff --git a/src/subspace.js b/src/subspace.js index bb06ccc..d09112d 100644 --- a/src/subspace.js +++ b/src/subspace.js @@ -54,8 +54,6 @@ export default class Subspace { throw new Error("please pass a contract instance to Subspace.contract()") } - console.dir(contractInstance) - let address = (contractInstance.options && contractInstance.options.address) || contractInstance.address || contractInstance.deployedAddress; let abi = (contractInstance.options && contractInstance.options.jsonInterface) || contractInstance.abi || contractInstance.abiDefinition; let from = (contractInstance.options && contractInstance.options.from) || contractInstance.from || contractInstance.defaultAddress || this.web3.defaultAccount; From 4dcc58ca3ef2ec074812a9fca8582df78c9f5e4e Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 3 Oct 2019 15:28:29 -0400 Subject: [PATCH 2/2] Add .track() to all events --- src/subspace.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/subspace.js b/src/subspace.js index d09112d..faa914d 100644 --- a/src/subspace.js +++ b/src/subspace.js @@ -66,6 +66,10 @@ export default class Subspace { return this.trackEvent(SubspaceContract, eventName, filterConditionsOrCb); } + Object.keys(SubspaceContract.events).forEach(ev => { + SubspaceContract.events[ev].track = (filterConditionsOrCb) => this.trackEvent(SubspaceContract, ev, filterConditionsOrCb); + }); + SubspaceContract.trackProperty = (propName, methodArgs, callArgs) => { return this.trackProperty(SubspaceContract, propName, methodArgs, callArgs); }