Created
May 20, 2019 00:44
-
-
Save siassaj/4fdf699634971d78f119f00a8e62621f 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
export function mix< | |
COMB extends { | |
[CS in keyof ComponentSinks]?: (arg: { | |
[K in keyof COMPONENTS]: Stream<any> | |
}) => ComponentSinks[CS] | |
}, | |
COMPONENTS extends { | |
[COMPNAME in keyof COMPONENTS]: { | |
[SINKNAME in keyof ComponentSinks]?: (COMB[SINKNAME] extends (arg: infer STREAMS) => any ? ( | |
COMPNAME extends keyof STREAMS ? STREAMS[COMPNAME] : ComponentSinks[SINKNAME] | |
) : ComponentSinks[SINKNAME]) | |
} | |
} | |
>(componentSinks: COMPONENTS, combines?: COMB): Partial<ComponentSinks>{ | |
// Get all unique keys present in the array of sinks | |
const keys = _.flow([ | |
_.values, | |
o => _.map(o, _.keys), | |
_.flatten, | |
_.uniq | |
])(componentSinks) | |
// array of arrays containing key & mixed sinks, or each key | |
const arrys = _.map(keys, key => { | |
// get object of sinks for the key containing undefineds in the right places | |
const streams = _.flow([ | |
sinks => _.map(sinks, (sink, component) => [component, sink[key]]), | |
_.fromPairs | |
])(componentSinks) | |
const mixed$ = doCombine(combines, key, streams) | |
const memoryMixed$ = key == "Layout" ? | |
mixed$.remember() | |
: | |
mixed$ | |
return [key, mixed$] | |
}) | |
// Create an object with keys as keys and values as merged streams | |
return _.fromPairs(arrys) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment