-
Notifications
You must be signed in to change notification settings - Fork 8
Shorthand
James edited this page May 30, 2017
·
3 revisions
👂 shorthand
🎼
shorthand easy helper functions
iterates over methods, binds them to the instance
chain.bindMethods(methods: Array<string>): Chain
iterates over methods, wraps them so their value returns Chain
chain.chainWrap(methods: Array<string>): Chain
class Eh extends Chain {
constructor(parent) {
super(parent)
this.chainWrap(['canada'])
}
canada(arg) {
console.log(arg)
}
}
const eh = new Eh()
eh.canada('log me') // this now returns Eh
set the value if it hasn't been set already
.setIfEmpty(key: Primative | Object, value: any)
new Chain()
.set('eh', true)
.setIfEmpty('eh', false) // eh is already set, ignored
.setIfEmpty('canada', true) // canada is not set, so it .sets it
// same as doing this
// if (chain.has('eh') === false) chain.set('eh', false)
// or
// chain.when(!chain.has('eh'), c => c.set('eh', false))
simply a function to return a value, to keep a single chain when there are scoped variables
same as return
but calls val if it's a function, and returns chain