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

♻ PoC navigators with set #294

Merged
merged 15 commits into from Jun 6, 2018
Merged

♻ PoC navigators with set #294

merged 15 commits into from Jun 6, 2018

Conversation

nlepage
Copy link
Member

@nlepage nlepage commented May 29, 2018

No description provided.

@nlepage nlepage added this to the 2.0 milestone May 29, 2018
@nlepage nlepage self-assigned this May 29, 2018
@nlepage nlepage changed the base branch from master to dev May 29, 2018 13:06
@codecov-io
Copy link

codecov-io commented May 29, 2018

Codecov Report

Merging #294 into dev will decrease coverage by 0.84%.
The diff coverage is 96%.

Impacted file tree graph

@@           Coverage Diff            @@
##            dev     #294      +/-   ##
========================================
- Coverage   100%   99.15%   -0.85%     
========================================
  Files        97      105       +8     
  Lines       285      356      +71     
========================================
+ Hits        285      353      +68     
- Misses        0        3       +3
Impacted Files Coverage Δ
packages/immutadot/src/util/lang.js 100% <ø> (ø) ⬆️
packages/immutadot/src/nav/indexNav.js 100% <100%> (ø)
packages/immutadot/src/nav/baseNav.js 100% <100%> (ø)
packages/immutadot/src/nav/arrayNav.js 100% <100%> (ø)
packages/immutadot/src/nav/propNav.js 100% <100%> (ø)
packages/immutadot/src/nav/objectNav.js 100% <100%> (ø)
packages/immutadot/src/core/set.js 100% <100%> (ø) ⬆️
packages/immutadot/src/nav/sliceNav.js 100% <100%> (ø)
packages/immutadot/src/nav/propsNav.js 83.33% <83.33%> (ø)
packages/immutadot/src/nav/nav.js 91.66% <91.66%> (ø)
... and 8 more

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 fb32ab7...77f9857. Read the comment docs.

@nlepage
Copy link
Member Author

nlepage commented May 29, 2018

🎉

    Update small todos list (1000 items):
      ES2015 destructuring: ~14828ops/s (0.07ms/op) on 50000ops
      immutable 3.8.2 (w/o conversion to plain JS objects): ~4400ops/s (0.23ms/op) on 50000ops
      immer 1.2.0 (proxy implementation w/o autofreeze): ~2226ops/s (0.45ms/op) on 50000ops
      qim 0.0.52: ~9766ops/s (0.10ms/op) on 50000ops
      immutad●t 2.0.0: ~11133ops/s (0.09ms/op) on 50000ops

    Update medium todos list (10000 items):
      ES2015 destructuring: ~1459ops/s (0.69ms/op) on 5000ops
      immutable 3.8.2 (w/o conversion to plain JS objects): ~413ops/s (2.42ms/op) on 5000ops
      immer 1.2.0 (proxy implementation w/o autofreeze): ~223ops/s (4.49ms/op) on 5000ops
      qim 0.0.52: ~934ops/s (1.07ms/op) on 5000ops
      immutad●t 2.0.0: ~1082ops/s (0.92ms/op) on 5000ops

    Update large todos list (100000 items):
      ES2015 destructuring: ~102ops/s (9.77ms/op) on 500ops
      immutable 3.8.2 (w/o conversion to plain JS objects): ~41ops/s (24.54ms/op) on 500ops
      immer 1.2.0 (proxy implementation w/o autofreeze): ~20ops/s (49.07ms/op) on 500ops
      qim 0.0.52: ~85ops/s (11.80ms/op) on 500ops
      immutad●t 2.0.0: ~104ops/s (9.60ms/op) on 500ops

@nlepage nlepage changed the title ♻ Use navigators to replace apply ♻ PoC navigators with set May 30, 2018
@nlepage nlepage removed the 🚧 WIP label May 30, 2018
@nlepage
Copy link
Member Author

nlepage commented May 30, 2018

@frinyvonnick
This is ready for review.
JSDoc and specific tests for each navigator will be added in further PRs.


export class ArrayNav extends BaseNav {
get length() {
if (this._length === undefined) this._length = length(this.value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this optimization really efficient ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right, I'll remove this

copy() {
const { value } = this
if (isNil(value)) return []
return Array.isArray(value) ? [...value] : { ...value }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you testing if this is an Array whereas we are in ArrayNav ?

Copy link
Member Author

@nlepage nlepage Jun 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because users might use slice or array index notation on an object, this is to avoid replacing the object by an array.

This conforms to normal JavaScript behavior:

const obj = {}
obj[0] = 'val'
console.log(obj) // Outputs: {0: "val"}

class IndexNav extends ArrayNav {
constructor(value, index, next) {
super(value, next)
this._index = index
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is appropriate, let's close our eyes on the ugly # and try this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find the babel plugin corresponding to the proposal.

I think it's time to rewrite in TS...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK it seems to be in babel 7 beta 48, it might be risky to upgrade to babel 7 but I'll give it a try...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if (isNil(value)) return []

return Array.from(range, index => _next(value[index]).get())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@nlepage
Copy link
Member Author

nlepage commented Jun 6, 2018

I'll try upgrading to babel 7 and using private fields in another PR.

@nlepage nlepage merged commit dfb76d4 into dev Jun 6, 2018
@nlepage nlepage deleted the refactor/nav branch June 6, 2018 21:00
nlepage added a commit that referenced this pull request Jan 22, 2019
* 🚧 PoC nav

* 🚧 Add index navigator

* 🚧 Add slice navigator

* ♻️ Reorganize code

* ♻️ Move apart get and update logic and use ES6 classes

* 🔥 Remove unused currification level

* ⚡ Use nav in set and validate performance improvement with benchmark

* ✨ Put back negative array index support

* ✅ Report apply tests to nav

* 🚚 Move each navigator in its own file as suggested by @frinyvonnick

* :refactor: Optional currying on set

* ✨ Add all props navigator

* ✨ Prop list navigator

* ♻️ Put TypeError for empty path in nav

* 👌 @frinyvonnick's review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants