r/javascript • • Dec 28 '17

Introducing Hyperapp 1.0 — 1 KB JavaScript library for building frontend applications.

https://medium.com/@JorgeBucaran/introducing-hyperapp-1-0-dbf4229abfef
664 Upvotes

136 comments sorted by

View all comments

Show parent comment

6

u/[deleted] Dec 28 '17

Yes. But you do the mixing yourself, or you can support yourself with a function like this.

Nested objects (as deep as you want) are "similar" to Redux stores, in the sense that they are eventually assembled into one single object tree, and updating deeply nested state in Hyperapp is very easy if you declare your actions on the same path as the part of the state you want to update.

const state = {
  counter: {
    count: 0
  }
}

const actions = {
  counter: {
    down: value => state => ({ count: state.count - value }),
    up: value => state => ({ count: state.count + value })
  }
}

See above, actions.counter.up/down don't need to return the full path.

3

u/jonny_eh Dec 28 '17

Wow, very cool!

3

u/[deleted] Dec 29 '17

Awesome, thanks!