You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
not an issue, more of a discussion...
so I was shopping around looking for the best way to support Immutable.js with redux.
I ended up coming up with a solution which works really nice, it gives you the full support of Typescript's typing and it allows you to inject any class instance into redux so you have full typing support around your redux functions.
import {Map} from 'immutable';
import { UUID } from 'angular2-uuid';
/**
* StoreModel is a thin wrapper of Immutable data around for a Class
* uses the internal immutable map to hold all values.
* This allows us a base class on which we can extend and inject
* into any Redux store as we follow Immutability
*
* Also ships with a helper static method to create unique IDs
**/
export class StoreModel {
static UniqueId(){
return UUID.UUID();
}
constructor(data:any = {}) {
this._data = Map<string, any>(data);
}
_data:Map<string, any>;
public setKey<T>(ClassName:any, key:string, value:any):T {
return this.setData(ClassName, this._data.set(key, value)) as T;
}
public getKey(key:string) {
return this._data.get(key);
}
public setData<T>(ClassName, data:any):T {
function ClassFactory(className:{new(data): T;}, data:any):T {
var created:T = new className(Map<string, any>(data));
return created;
}
return ClassFactory(ClassName, data);
}
public getData():Map<string, any> {
return this._data;
}
}
and so you can simply extend the base such as a Todo:
Hi, thank you for sharing. In general we recommend that both actions and the state are plain objects (or something like Immutable Maps) so they are easy to serialize, record and replay, hydrate and dehydrate.
not an issue, more of a discussion...
so I was shopping around looking for the best way to support Immutable.js with redux.
I ended up coming up with a solution which works really nice, it gives you the full support of Typescript's typing and it allows you to inject any class instance into redux so you have full typing support around your redux functions.
and so you can simply extend the base such as a Todo:
and insert that todo into redux with all the goodness of typing support
and you also get the same typing support on the subscription side:
full source @: https://github.com/born2net/ng2Boilerplate
works GREAT...
Sean
The text was updated successfully, but these errors were encountered: