Last active
October 4, 2017 11:43
-
-
Save baranovxyz/10d3aae7891e6f743e73bf313cc40363 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* To avoid null state | |
*/ | |
export const NullableComponent = ( | |
component: Component, | |
vnodeForNull: VNode | null = null, | |
componentSinks: Array<string> = ["DOM", "onion"] | |
) => (sources: Sources): Sinks => { | |
const t$ = sources.onion.state$.map( | |
state => | |
state === null | |
? { | |
DOM: xs.of( | |
vnodeForNull !== null ? vnodeForNull : <div>No data</div> | |
) | |
} | |
: component(sources) | |
); | |
return componentSinks | |
.map(sinkName => [ | |
[sinkName], | |
t$.map(s => R.propOr(xs.of(), sinkName, s)).flatten() | |
]) | |
.reduce((acc, val) => ({ ...acc, [val[0]]: val[1] }), {}); | |
}; | |
// lens | |
export const currentProjectLens = { | |
get: state => state.projects.find(p => p._id === state.app.projCurId) || null, | |
set: (state, childState) => ({ | |
...state, | |
projects: state.projects.map( | |
(item: any) => (item._id === childState._id ? childState : item) | |
) | |
}) | |
}; | |
// connecting component | |
const projectContainer = isolate( | |
NullableComponent(ProjectContainer, null, ["DOM", "onion", "feathers"]), | |
{ onion: currentProjectLens } | |
)(sources); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment