Skip to content

Commit

Permalink
perf(web3): Remove dependenecies
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The provider option has been removed.
Create and pass your web3 instance directly into the library.
  • Loading branch information
morrislaptop committed Mar 17, 2018
1 parent 832c576 commit cb1c870
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 197 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ In module environments, e.g CommonJS:

``` js
var Vue = require('vue')
var Web3 = require('web3')
var VueWeb3 = require('vue-web3')

// explicit installation required in module environments
Vue.use(VueWeb3, { provider: web3.currentProvider })
Vue.use(VueWeb3, { web3: new Web3(web3.currentProvider) })
```

## Usage
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@
"microbundle": "^0.4.4",
"semantic-release": "^12.4.1",
"truffle": "^4.1.0",
"vue": "^2.5.13"
"vue": "^2.5.13",
"web3": "^1.0.0-beta.31"
},
"scripts": {
"dev": "microbundle watch",
"build": "microbundle",
"test": "truffle test",
"prepublishOnly": "yarn build"
},
"dependencies": {
"bluebird": "^3.5.1",
"lodash": "^4.17.5",
"web3": "^1.0.0-beta.30"
"peerDependencies": {
"web3": "^1.0.0"
}
}
18 changes: 7 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const Web3 = require('web3')
const Promise = require('bluebird')
const _ = require('lodash')

module.exports = (Vue, options) => {

let web3 = options.web3 || new Web3(options.provider)
let web3 = options.web3
let callsToCheck = []

web3.eth
Expand All @@ -14,7 +10,8 @@ module.exports = (Vue, options) => {
async function onNewBlockHeaderData(blockHeader) {
if (! blockHeader.number) return

await Promise.delay(12000) // allow node to get the txns in the block
// allow node some time to get the txns in the block
await new Promise(resolve => setTimeout(resolve, options.delay || 12000))

let block = await web3.eth.getBlock(blockHeader.number, true)

Expand Down Expand Up @@ -73,12 +70,11 @@ module.exports = (Vue, options) => {
var bindings = this.$options.web3
if (typeof bindings === 'function') bindings = bindings.call(this)
if (! bindings) return

let calls = _.pickBy(bindings, value => value.method)
Object.keys(calls).forEach(key => this.$bindCall(key, calls[key]))

let events = _.pickBy(bindings, value => value.event)
Object.keys(events).forEach(key => this.$bindEvents(key, events[key]))
Object.keys(bindings).forEach(key => {
if (bindings[key].method) this.$bindCall(key, bindings[key])
if (bindings[key].event) this.$bindEvents(key, bindings[key])
})
}
})
}
Loading

0 comments on commit cb1c870

Please sign in to comment.