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.

Simpler and more intuitive way to do attach(Downgrade)

See original GitHub issue

We tried to implement hookstate into our serverless app and we needed to send objects from the state to the firebase database. However, in order to do so, we needed to do the following:

const data = myState.attach(Downgraded).get()

This has one main issue, which is the reason we scrapped hookstate in favor of something else. It’s not intuitive, a person who hasn’t read the docs a couple of times won’t know what is going on. It’s also really counter intuitive how .get() returns you a proxy, which can’t be used directly in JSON API request. I get that there has to be a reason to force everything to need Downgraded attached to get the pure value, but the way it has to be done is ugly. I suggest creating a function toObject() which can attach Downgraded internally, but it just has better code flow. The example from above would become the following:

const data = myState.toObject().get()

or

const data = myState.get().toObject()

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
avkonstcommented, Jun 20, 2022

Hookstate 4: State method get has options. One of it allows to remove proxy wrapping:

let state = useState(...)
state.get({ noproxy: true }) // returns the value state without proxy wrapping

New Extensions API allows to add extension methods, so it is easy to add an extension method which would do get({ noproxy: true }) inside. An extension method or property can have any name, so anything of the following could be possible:

let state = useState(..., () => MyExtensionToGetValueWithoutProxy())
// assuming the extension implements the following methods, any name is possible:
state.unwrap()
state.raw()
state.data
///....

Documentation updates are pending.

3reactions
arbobcommented, Oct 21, 2021

No problems. What would be the best name for the new property? I am thinking of giving it the name origin?

I’d vote for a simpler and intuitive state.value.get().

Read more comments on GitHub >

github_iconTop Results From Across the Web

example for CI upgrade,downgrade,switch in CMDB
Hi there,. I hope this will help... Reclassify a CI by modifying its 'Class' attribute. You can upgrade, downgrade or switch a CI's...
Read more >
How to Downgrade an App Android - Alphr
1. Navigate to the folder that stores the app and delete its APK file. The APK file is actually the installable part of...
Read more >
[5 Ways] Downgrade Windows 10 Enterprise to Pro Without ...
How to downgrade Windows 10 Enterprise to Pro without losing data? Here are 5 practical methods that you can try!
Read more >
How to Downgrade iOS 13 without Losing Data in Easy Steps
Select “Repair”; the software begins iOS 13 downgrade to 12 on the iDevice. The device must remain connected until the repair process is...
Read more >
New 'Downgrade' QBO Subscription Plan Functionality
Essentially, all the accounting integrity is kept, but there are some feature restrictions. This means some features will not be included in the ......
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