feat: add null coalesce and optional chaining (#70)

This commit is contained in:
Richard Ramos 2020-02-14 18:52:01 -04:00 committed by GitHub
parent 65c2cb1799
commit 2646cd58d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 11 deletions

View File

@ -5,4 +5,5 @@ subspace.db
examples/
test/
.editorconfig
TODO
TODO
coverage/

View File

@ -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"
]
}
},

View File

@ -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",

View File

@ -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);

View File

@ -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);

View File

@ -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;