Skip to content
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

feat: immutable storage #936

Merged
merged 3 commits into from
Aug 28, 2018
Merged

feat: immutable storage #936

merged 3 commits into from
Aug 28, 2018

Conversation

faustbrian
Copy link
Contributor

@faustbrian faustbrian commented Aug 28, 2018

Proposed changes

This PR provides an immutable storage in the form of the new package core-storage. This package makes use of https://facebook.github.io/immutable-js/ under the hood so everything that can be done by immutable.js can be done with core-storage.

core-storage only is a wrapper around immutable.js in order to make it possible to have a shared instance for in-memory information that all plugins and core itself can access at any time without having to worry about the data in it getting modified without being told to do so.

We could use this storage for peers, wallets, blockchain state, blocks and many more things were we need the certainty that the data stays how it was stored.

The usage is pretty simple, an example would be the wallet manager. Below example demonstrates how we replace POJOs with the immutable storage provided by core-storage.

const container = require('@arkecosystem/core-container')
const storage = container.resolvePlugin('storage')

// Old way
this.walletsByAddress = {}
this.walletsByAddress[address] = address

// New way
this.walletsByAddress = storage.createMap('wallets.byUsername', {})
this.walletsByAddress.set(address, wallet)

Lays the groundwork to work on #818, #851, #850.

This PR only provides the storage. Integration into core plugins will be done after this is merged.

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING documentation
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Signed-off-by: Brian Faust <envoyer@pm.me>
Brian Faust added 2 commits August 28, 2018 07:50
Signed-off-by: Brian Faust <envoyer@pm.me>
Signed-off-by: Brian Faust <envoyer@pm.me>
@codecov-io
Copy link

codecov-io commented Aug 28, 2018

Codecov Report

Merging #936 into develop will decrease coverage by 0.27%.
The diff coverage is 0%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #936      +/-   ##
===========================================
- Coverage    52.82%   52.54%   -0.28%     
===========================================
  Files          432      434       +2     
  Lines         7205     7243      +38     
  Branches       927      931       +4     
===========================================
  Hits          3806     3806              
- Misses        2975     3009      +34     
- Partials       424      428       +4
Impacted Files Coverage Δ
packages/core-storage/lib/storage.js 0% <0%> (ø)
packages/core-storage/lib/index.js 0% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9c79a14...cddd2da. Read the comment docs.

@faustbrian faustbrian merged commit 6ec0cf7 into develop Aug 28, 2018
@faustbrian faustbrian deleted the feat/immutable-storage branch August 28, 2018 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants