Skip to content

Conversation

Mytrill
Copy link
Contributor

@Mytrill Mytrill commented Oct 22, 2017

This PR addresses #418 and #425.

The approach here is to recursively modify the update function as we initialize the actions/modules.

EDIT1: Gzipped size (without the console.log...): 1476 bytes
EDIT2: after commit 7b839a5 size is: 1492 bytes (but the code is easier to understand IMHO)
EDIT3: 1487 bytes (with fix to #438)

@codecov
Copy link

codecov bot commented Oct 22, 2017

Codecov Report

Merging #426 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #426   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           2      2           
  Lines         133    139    +6     
  Branches       40     39    -1     
=====================================
+ Hits          133    139    +6
Impacted Files Coverage Δ
src/app.js 100% <100%> (ø) ⬆️

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 0d0a888...1998726. Read the comment docs.

@Mytrill
Copy link
Contributor Author

Mytrill commented Oct 22, 2017

Other way to write this PR (by passing a path down the init()/initActions() functions + using getPath()/setPath() from #425) at this branch: https://github.com/Mytrill/hyperapp/tree/immutable-state-2

Gzipped size for this branch: 1535 bytes.

@lukejacksonn
Copy link
Contributor

lukejacksonn commented Oct 23, 2017

It is going to take me a while to comprehend this.. do you have a branch/commit with comments included at all? 😅 (no worries if not)

@jorgebucaran
Copy link
Owner

jorgebucaran commented Oct 23, 2017

Comments please or just add here/below an explanation of what's happening in there! 🙏

/cc @Mytrill

src/app.js Outdated
}

function globalUpdate(result) {
console.log("Calling global update with result: " + JSON.stringify(result))
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this is here as a clue! 🕵️😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will remove this.

@lukejacksonn
Copy link
Contributor

I haven't checked the diff.. but I think I prefer the approach here https://github.com/Mytrill/hyperapp/tree/immutable-state-2

@Mytrill
Copy link
Contributor Author

Mytrill commented Oct 25, 2017

https://github.com/Mytrill/hyperapp/tree/immutable-state-2 is much easier to understand (pass the current path to init() and initActions() and always get(globalState, path) to get the current slice or set(globalState, path, result) to merge in the actions results.

I will play around a bit more with both versions but probably end up doing another PR with the other branch, this one is too complicated, it's not worth the ~50 bytes difference (unless someone disagree, in which case I'll try to write down how the code in this PR works.).

@jorgebucaran
Copy link
Owner

@Mytrill Can you just push on top of this PR? Don't push force, just add another commit with the changes. 🙏

src/app.js Outdated
globalState,
globalActions,
updateGlobalState,
getGlobalState
Copy link

@Pyrolistical Pyrolistical Oct 27, 2017

Choose a reason for hiding this comment

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

saves 3 bytes if we inline getGlobalState with

function() {
  return globalActions
}

Minified uncompressed

Before 3349 bytes
After 3346 bytes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in the next commit.

// do not override state is already exist in current module
state[key] || (state[key] = {}),
// do not override actions is already exist in current module
actions[key] || (actions[key] = {}),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should solve #438.

Copy link
Owner

Choose a reason for hiding this comment

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

@Mytrill My PR doesn't have this, is it necessary?

@jorgebucaran jorgebucaran merged commit 81d4235 into jorgebucaran:master Nov 4, 2017
@jorgebucaran
Copy link
Owner

Thanks @Mytrill! 🎉

@jorgebucaran jorgebucaran added the enhancement New feature or request label Nov 4, 2017
jorgebucaran pushed a commit that referenced this pull request Jan 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants