Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A terse API for performing tricky deep patches
export {patch, scope}
function patch(a, b){
for(var key in b)
if(b.hasOwnProperty(key))
a[key] = (
b[key] instanceof scope
? scope.apply(a[key])
: b[key]
)
return a
}
function scope(input){
if(!(this instanceof scope))
return new scope(input)
this.apply = function(consumer){
return consumer(input)
}
}
/*
import {patch as p, scope as s} from 'patchinko'
p(config, {
css: s(css => p(css, {
labels: [x, y, z]
})),
onClick: s(onClick =>
function(event){
var outcome = onClick(...arguments)
if(outcome != desired)
return false
else
return outcome
})
)
})
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment