Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

addCallback to execute a function after state change. #29

Closed
rotoxl opened this issue Dec 5, 2018 · 9 comments
Closed

addCallback to execute a function after state change. #29

rotoxl opened this issue Dec 5, 2018 · 9 comments
Assignees
Labels
feature A new feature is requested.
Milestone

Comments

@rotoxl
Copy link

rotoxl commented Dec 5, 2018

Hi there,

I'm wondering If there's a chance to get some persistence & rehydration. I'm considering to use it for a new react-native app and not having such would be a stopper

Thanks

@quisido
Copy link
Collaborator

quisido commented Dec 5, 2018

Are you talking about for SSR? Can you elaborate on how you want state to persist and how you would want it to rehydrate?

@quisido quisido added feature A new feature is requested. help wanted The owner cannot resolve this on their own. labels Dec 5, 2018
@quisido quisido self-assigned this Dec 5, 2018
@quisido quisido changed the title Persistence and rehydration? State persistence? Dec 10, 2018
@quisido
Copy link
Collaborator

quisido commented Dec 10, 2018

I'm changing this to just a request for state persistence, as rehydration between server and client exists as issue #9.

I would still need more information to tackle this request, though. I'm not sure what specifically you are requesting in relation to a React Native application.

@rotoxl
Copy link
Author

rotoxl commented Dec 11, 2018

Hi! sorry for the delay. My request was not about server side rendering, it was about persistence and (after cold start) retrieving that data from storage (the term rehydration means that in redux persistence - https://github.com/rt2zz/redux-persist). It just handles the 'asynchronicity' of a cold start to initialize the store with the latest bunch of data, IIUC

@quisido
Copy link
Collaborator

quisido commented Dec 12, 2018

I understand. You want persistence of state between application launches.

I think "afterware" support may allow for this. Something like useAfterware(functionThatReceivesStateOnChange) will allow custom functionality, like writing to storage when the state changes.

useAfterware(function(global) {
  persistentStorage.set('global', JSON.stringify(global));
});
// The above function executes with the new global state whenever setGlobal occurs.

If something like this sounds good to you, I'll mark it as TODO. I want to make sure it matches your use case.

@rotoxl
Copy link
Author

rotoxl commented Dec 13, 2018

Yes, I think that would cover the lifecycle of any mobile app (which usually follow an offline-first approach).

Used in conjunction with componentDidMount (pseudo code):

//based in the example from reactn/Examples/Class Components
export default class MyView extends React.Component {
 ...
  componentDidMount() {
     persistentStorage.get('global', (value)=>{
         this.setGlobal(
                  JSON.parse(value)
         )
     })
  }

  render() {
    ...
}

Thanks for your work.

@darbio
Copy link

darbio commented Jan 29, 2019

Was this implemented? Is there a way to hook into setGlobal with the current release?

@quisido quisido added this to the 0.2.0 milestone Jan 30, 2019
@quisido
Copy link
Collaborator

quisido commented Jan 30, 2019

This has not been done yet. I have been out for various reasons the past month and have returned to my development life as of today.

@quisido quisido changed the title State persistence? useAfterware to execute a function after state change. Feb 1, 2019
@quisido
Copy link
Collaborator

quisido commented Feb 1, 2019

I'd just like to state that I have this existing in my local repository (using the name addCallback), but it's pretty important to me that I get unit tests completed for the project as a whole before cutting a new version, so I do not have an ETA on release. I may do an alpha release if the unit tests delay this too much.

@quisido quisido removed the help wanted The owner cannot resolve this on their own. label Feb 1, 2019
@quisido quisido assigned quisido and unassigned quisido Feb 1, 2019
@quisido quisido closed this as completed in 89fe07f Feb 2, 2019
@quisido
Copy link
Collaborator

quisido commented Feb 4, 2019

I have released reactn@0.2.0 to include this functionality as addCallback. The documentation for addCallback has been added to the README.

I added some unit tests and manual app testing to try to insure there were no breaking changes, but this version included a major change to some internal workings. I would love some community feedback on if any errors are discovered.

Thank you for your patience. I'm sorry about the long delay. I have been unable to contribute for the past month, but I'm hoping to begin knocking out a lot of ReactN's open issues now.

@quisido quisido changed the title useAfterware to execute a function after state change. addCallback to execute a function after state change. Feb 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature A new feature is requested.
Projects
None yet
Development

No branches or pull requests

3 participants