question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[question] deep state, destructuring & action verbosity/DRY

See original GitHub issue

hey guys,

i don’t believe there is something like concise notation for deep destructuring:

const x = ({a.b.c}) => c.foo;

most examples with hyperapp use a flat state, so they look simple. but the app size will grow rather quickly and become less DRY as you have to repeat the state structure in multiple places. adding just one level to the counter example results in a lot more repetitive action code, or any code that can return partial state (but must be aware of the entire ancestor state structure): https://codepen.io/anon/pen/ZJrrGW?editors=0010

attempts to make it smaller [understandably] don’t quite work: https://codepen.io/anon/pen/MvQQje?editors=0010

thoughts? thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:49 (30 by maintainers)

github_iconTop GitHub Comments

5reactions
leeoniyacommented, Aug 18, 2017

ā€œAll problems in computer science can be solved by another level of abstraction…except for the problem of too many levels of abstraction.ā€ [1]

šŸ˜„

[1] https://en.wikipedia.org/wiki/Indirection

4reactions
jorgebucarancommented, Aug 19, 2017

Okay, I think I have an idea… šŸ’”

actions: {
  up(state, actions) {
    return ["count", "realCount", state => state + 1]
  }
}

or

actions: {
  upAndMore(state, actions) {
    return [
      ["count", "realCount", state => state + 1]
      ["some", "more", "stuff", state => state + "foo"]
    ]
  }
}

Definitely an improvement of the weird state(path, fn) syntax a few posts above and a possibility now that the state is POJO.

Also, this ~might be~ is possible to implement outside core as a mixin using thunks and resolve.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using ES6 To Destructure Deeply Nested Objects in ... - ITNEXT
Today, I will show you how to use ES6 to destructure nested objects, my friends, AND what's more, prevent the dreaded undefined error...
Read more >
Destructuring assignment - JavaScript - MDN Web Docs
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties fromĀ ...
Read more >
ES6 deep nested object destructuring - Stack Overflow
I would like to extract statement object and the isConfirmed property in the same line. const { statement: { isConfirmed }, statement }...
Read more >
Destructuring assignment - The Modern JavaScript Tutorial
Destructuring assignment is a special syntax that allows us to ā€œunpackā€ arrays or objects into a bunch of variables, as sometimes that'sĀ ...
Read more >
Removing Object Properties with Destructuring
Object destructuring allows us to create variables from object property names, ... for writing JavaScript and managing state (state being our data )....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found