-
Notifications
You must be signed in to change notification settings - Fork 49
feat: add isInitialized method #219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
A few places need ot know whether or not a repo has been initialized and do so by a variety of methods - checking whether certain files exist, etc. This PR adds an `isInitialized()` method to the ipfs repo class to take some of this guesswork away as the repo will know if it's been initialized.
src/index.js
Outdated
| try { | ||
| await this._openRoot() | ||
| await this._checkInitialized() | ||
| // necessary? await this.root.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to detect initialization without opening the root store?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only in node, in the browser you have to open the store first.
Ask the repo if it has been initialised, if so, allow the user to
skip the `.init()` step and move on to `.start()`
Removes the proxy api object in favour of vanilla functions because
it was causing errors to be thrown if you even referenced properties
that were from a different api state.
E.g. with an unitialised repo:
```javascript
const ipfs = await IPFS.create({
init: false,
start: false
})
// no invocation, just referencing the property causes an error to be thrown
console.info(ipfs.start)
```
I'd looked at changing the proxy behaviour to return a function that
throws if invoked, but at the time the proxy is called you don't know
what the calling code is going to do with the return value so it's hard
to know if it's accessing a function or a property - the return value is
just put on the stack and interacted with so it seemed simpler to just
pull it out and define the API up front.
A nice future improvement might be to have `.init`, `.start` and `.stop`
export functions that update the API - that way after `.stop` has been
invoked, it could restore the API from the post-`.init` state, but this
can come later.
Also upgrades `ipfsd-ctl` to pass refs only during factory creation.
Depends on:
- [ ] ipfs/js-ipfsd-ctl#457
- [ ] ipfs/js-ipfs-repo#219
- [ ] ipfs-inactive/npm-go-ipfs-dep#40
alanshaw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌 beautiful
Ask the repo if it has been initialised, if so, allow the user to
skip the `.init()` step and move on to `.start()`
Removes the proxy api object in favour of vanilla functions because
it was causing errors to be thrown if you even referenced properties
that were from a different api state.
E.g. with an unitialised repo:
```javascript
const ipfs = await IPFS.create({
init: false,
start: false
})
// no invocation, just referencing the property causes an error to be thrown
console.info(ipfs.start)
```
I'd looked at changing the proxy behaviour to return a function that
throws if invoked, but at the time the proxy is called you don't know
what the calling code is going to do with the return value so it's hard
to know if it's accessing a function or a property - the return value is
just put on the stack and interacted with so it seemed simpler to just
pull it out and define the API up front.
A nice future improvement might be to have `.init`, `.start` and `.stop`
export functions that update the API - that way after `.stop` has been
invoked, it could restore the API from the post-`.init` state, but this
can come later.
Also upgrades `ipfsd-ctl` to pass refs only during factory creation.
Depends on:
- [ ] ipfs/js-ipfsd-ctl#457
- [ ] ipfs/js-ipfs-repo#219
- [ ] ipfs-inactive/npm-go-ipfs-dep#40
fix: do not allow parallel init, start or stop
If the user is calling `.init`, `.start` or `.stop` from the code
in multiple places simultaneously, they probably have a bug in
their code and we should let them know instead of masking it.
A few places need ot know whether or not a repo has been initialised and do so by a variety of methods - checking whether certain files exist, etc.
This PR adds an
isInitialized()method to the ipfs repo class to take some of this guesswork away as the repo will know if it's been initialised.