feat: add null coalesce and optional chaining (#70)
This commit is contained in:
parent
65c2cb1799
commit
2646cd58d1
|
@ -5,4 +5,5 @@ subspace.db
|
|||
examples/
|
||||
test/
|
||||
.editorconfig
|
||||
TODO
|
||||
TODO
|
||||
coverage/
|
|
@ -23,7 +23,9 @@ module.exports = api => {
|
|||
}
|
||||
],
|
||||
"@babel/plugin-proposal-class-properties",
|
||||
"@babel/plugin-proposal-private-methods"
|
||||
"@babel/plugin-proposal-private-methods",
|
||||
"@babel/plugin-proposal-nullish-coalescing-operator",
|
||||
"@babel/plugin-proposal-optional-chaining"
|
||||
]
|
||||
},
|
||||
browser: {
|
||||
|
@ -48,7 +50,9 @@ module.exports = api => {
|
|||
}
|
||||
],
|
||||
"@babel/plugin-proposal-class-properties",
|
||||
"@babel/plugin-proposal-private-methods"
|
||||
"@babel/plugin-proposal-private-methods",
|
||||
"@babel/plugin-proposal-nullish-coalescing-operator",
|
||||
"@babel/plugin-proposal-optional-chaining"
|
||||
]
|
||||
},
|
||||
module: {
|
||||
|
@ -73,7 +77,9 @@ module.exports = api => {
|
|||
}
|
||||
],
|
||||
"@babel/plugin-proposal-class-properties",
|
||||
"@babel/plugin-proposal-private-methods"
|
||||
"@babel/plugin-proposal-private-methods",
|
||||
"@babel/plugin-proposal-nullish-coalescing-operator",
|
||||
"@babel/plugin-proposal-optional-chaining"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
|
@ -43,6 +43,8 @@
|
|||
"@babel/plugin-proposal-class-properties": "^7.8.3",
|
||||
"@babel/plugin-transform-runtime": "^7.8.3",
|
||||
"@babel/plugin-proposal-private-methods": "^7.8.3",
|
||||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.8.3",
|
||||
"@babel/plugin-proposal-optional-chaining": "^7.8.3",
|
||||
"@babel/preset-env": "^7.8.4",
|
||||
"babel-eslint": "^10.0.3",
|
||||
"eslint": "^6.8.0",
|
||||
|
|
|
@ -49,7 +49,7 @@ class Database {
|
|||
|
||||
getLastKnownEvent(eventKey) {
|
||||
const collection = this.db.getCollection(eventKey);
|
||||
if (collection && collection.count()) {
|
||||
if (collection?.count()) {
|
||||
return collection.max("blockNumber");
|
||||
} else {
|
||||
this.db.addCollection(eventKey);
|
||||
|
@ -59,7 +59,7 @@ class Database {
|
|||
|
||||
getFirstKnownEvent(eventKey) {
|
||||
const collection = this.db.getCollection(eventKey);
|
||||
if (collection && collection.count()) {
|
||||
if (collection?.count()) {
|
||||
return collection.min("blockNumber");
|
||||
} else {
|
||||
this.db.addCollection(eventKey);
|
||||
|
|
|
@ -13,11 +13,11 @@ class EventSyncer {
|
|||
}
|
||||
|
||||
track(contractInstance, eventName, filters, gteBlockNum, networkId) {
|
||||
const eventKey = hash(Object.assign({address: contractInstance.options.address, networkId}, filters || {}));
|
||||
const eventKey = hash(Object.assign({address: contractInstance.options.address, networkId}, filters ?? {}));
|
||||
|
||||
this.db.deleteNewestBlocks(eventKey, gteBlockNum);
|
||||
|
||||
let filterConditions = Object.assign({fromBlock: 0, toBlock: "latest"}, filters || {});
|
||||
let filterConditions = Object.assign({fromBlock: 0, toBlock: "latest"}, filters ?? {});
|
||||
let lastKnownBlock = this.db.getLastKnownEvent(eventKey);
|
||||
let firstKnownBlock = this.db.getFirstKnownEvent(eventKey);
|
||||
|
||||
|
|
|
@ -33,9 +33,9 @@ export default class Subspace {
|
|||
this.web3 = new Web3Eth(provider);
|
||||
|
||||
this.options = {};
|
||||
this.options.refreshLastNBlocks = options.refreshLastNBlocks || 12;
|
||||
this.options.callInterval = options.callInterval || 0;
|
||||
this.options.dbFilename = options.dbFilename || "subspace.db";
|
||||
this.options.refreshLastNBlocks = options.refreshLastNBlocks ?? 12;
|
||||
this.options.callInterval = options.callInterval ?? 0;
|
||||
this.options.dbFilename = options.dbFilename ?? "subspace.db";
|
||||
this.options.disableDatabase = options.disableDatabase;
|
||||
|
||||
this.networkId = undefined;
|
||||
|
|
Loading…
Reference in New Issue