Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support patching non-React Component classes? #50

Closed
duncanmak opened this issue Jul 25, 2015 · 3 comments
Closed

Support patching non-React Component classes? #50

duncanmak opened this issue Jul 25, 2015 · 3 comments

Comments

@duncanmak
Copy link

Hello,

I noticed that if I save objects using LrAPI's setState and then get them back on reload, methods that were changed do not get patched onto the existing objects.

For example;

class Foo {
     constructor(name) { this.name = name; }
     toString() { return this.name; }
}

let instances = [new Foo('a'), new Foo('b'), new Foo('c')];
instances.map(i => i.toString()); // ['a', 'b', 'c']

lrApi.setState(instances);
// patch toString to return this.name.toUppercase() which will trigger reload

// expect ['A', 'B', 'C'], but I get ['a', 'b', 'c'] instead
lrApi.getState().map(i => i()); 

new Foo('d').toString() // 'D', as expected

If this is not supported, I'd love to contribute to the project so that this could work, I just need some pointers.

@milankinen
Copy link
Owner

Unfortunately setState and getState from livereactload-api is meant for plain data only.

What is your goal you are trying to solve with lrApi.setState? Perhaps there is a better way to solve it.

@duncanmak
Copy link
Author

I was inspired by the React Hot Loader talk at ReactEurope, so I set out to recreate what I saw using a different stack (browserify + livereactload + rxjs (instead of redux))

I have it basically working here - https://github.com/duncanmak/experiments/tree/action-playback/flux-by-rx

The main file that loads in the state is here - https://github.com/duncanmak/experiments/blob/action-playback/flux-by-rx/src/main.ts

I tried webpack and HMR and I also can't get it to do this same thing, perhaps I'll need to replace my Event objects with something simpler, alas 😞

@milankinen
Copy link
Owner

Ahh! Then you should definitely take look at ffux: https://github.com/milankinen/ffux

I'm also an enthusiastic FRP user so I implemented ffux especially React+FRP combo in my mind. Live reloading is also supported. Though the examples contain only Webpack version, the same code should work with LiveReactload too (and no lrApi should be needed at all!).

On 25.7.2015, at 21.21, Duncan Mak notifications@github.com wrote:

I was inspired by the React Hot Loader talk at ReactEurope, so I set out to recreate what I saw using a different stack (browserify + livereactload + rxjs (instead of redux))

I have it basically working here - https://github.com/duncanmak/experiments/tree/action-playback/flux-by-rx

The main file that loads in the state is here - https://github.com/duncanmak/experiments/blob/action-playback/flux-by-rx/src/main.ts

I tried webpack and HMR and I also can't get it to do this same thing, perhaps I'll need to replace my Event objects with something simpler, alas


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants