⛓ flipchain
core chaining library, heavily based on webpack-chain, but not webpack-specific.
🏰 benefits
writing an api using flipchain means writing a single fluent api, but getting 3 apis as a result!
- 🍉 rehydratable configurations
- ⛓ fluent chainable api
- 🍦 object configs that are easily merged deep
🌊 what?
imagine there are 2 people by the water, & the goal is to make 10 splashes.
as with most skills, you get better at skipping rocks the more that you do it. a lot of people cannot skip rocks, or they do not like to skip rocks, but they can still throw rocks and make a splash. think of this like non-fluent/vanilla-calls
ChainChainChain
or throwing a really huge rock into the water, and getting the splashes to make more splashes.
Chain
using method chaining looks similar to skipping rocks
Chain
writing an application with a fluent interface allows people to use it all three ways, and you only have to write it one way.
📘 examples
👋 intro
const ChainedMap = { superparent // extend a list of strings for easy chainable methods this // same as .extend, // but when called with no arguments, // default is used (`true` in this case) // third param is optionally a prefix for inversified // for example, `no` => `noCanada()` for inverse value this } // if more advanced data changes are needed // or if the syntax is preferred for use with typescript or flowtype // .set, .get, .has are available { this return this } { return this } // {igloo: 'fire', canada: false, eh: 'moose'}const config = // this is == configconst hydrated = // canada is now trueconst merged =
🕳🏊 advanced
const ChainedMap = const ChainedSet = static { return parent } { superparent thislist = this this this } { thislist return this } { this return this } { return Object } // since we have additional data that is not simple key value // we do additional (albeit easy) steps to rehydrate { super Object return this } // same with `from` // we do additional simple steps to merge in lists { Object // built-in merging // can use `.mergeReal` to merge only `real` values // and `.merge` to merge any super return this } const chain = Advanced // true, `eh!`chainchain const result = chain const hydrated = Advanced const merged = Advanced // can use toConfig,// and safely continue editing `merged`// with a snapshot of the object data saved as `mergedResult`const mergedResult = merged // hydrated === result === {// igloo: 'brr',// canada: 'canada',// eh: 'eh!',// list: [ 'thing one', 'thing two' ]// } // merged === {// igloo: 'whaaaat',// canada: 'canada',// eh: 'eh!',// list: [ 'thing one', 'thing two' ]// }
🌊 types
- there are jsdoc blocks for all methods
🌐 api
- every chain has
.className
for easy debugging - every chain has this.parent
- and this.parent is hidden on inspection by 🕵🗜 inspector-gadget for easier debugging
ChainedSet
- Set
- prepend => this
- clear => this
- delete => this
- values => array of entries
- has => boolean
- merge => merge an object into the chain
- when => conditional instance callback
ChainedMap
extendAlias
(methodsToAlias: Array<string>, methodToAlias: string, [thisArg])
- alias a list of methods
- @returns
this
from
(obj: Object)
- checks each property of the object
- calls the chains accordingly
- rehydrates a chain from an object
other
- decorateParent (using childparent)
- clear() => this // clearsAll
- delete(key) => this
- entries => {keysAndValues}
- values => Object.values
- get(key) => entry
- has(key) => boolean
- set(key, val) => this
if key is an array, merge in the value,
usually should use ChainedSet for this
- concat(key, val) => this
- append(key, val) => this
merging
- mergeReal(obj) => this // only merges non-undefined values
- merge(obj) => this
- clean => this
- when => conditional instance callback
🔗 links & more
chainMapTill
lets you chain until the required keys are set via chains, or if they are passed in, then it auto returns parent
chainedMapExtendable
- has chains with
.extends
able to usedefault
values when calling it - also can add
prefixes
(defaultno
) so if you usecache
defaulttrue
, it can addnoCache
which does the inverse - set up for being chains of chains when you add a few decorating chains dynamically
📝🌊 TODO
// using `izz` to validate types when setting this