Create a gist now

Instantly share code, notes, and snippets.

Embed
mimix
const {assign, keys} = Object
const scope = fn =>
function(){
return fn(x => x.apply(this, arguments))
}
const compose = (key, values) => (
key === 'view'
?
values.pop()
:
typeof value[0] === 'function'
?
functions(key, values)
:
key === 'style'
?
Object.assign({}, ...values)
:
key === 'class' && key === 'className'
?
values.join(' ')
:
values.pop()
)
const functions = (key, values) => (
key === 'onbeforeremove'
?
scope(apply => Promise.all(values.map(apply)))
:
key === 'onbeforeupdate'
?
scope(apply => !values.map(apply).every(x => x === false))
:
scope(apply => values.forEach(apply))
)
const mimix = (...entities) =>
keys(assign({}, ...entries))
.map(key => [
key,
entities
.reduce(x => x.key)
.filter(x => x)
])
.reduce(
(mix, pair) => (
mix.key = compose(pair),
mix
),
{}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment