obj-chain-core
Version:
fluent chaining for obj with dot-prop access
48 lines (39 loc) • 1.13 kB
JavaScript
// similar to GQL, could match data, properties, and values
.whenIncl('config.navigation', item)
.otherwise()
.push('config.navigation', item)
class Store extends ChainedMap {
constructor(parent) {
super(parent)
}
exec(str, ...args) {
var bits = str.split('.')
var cmd = bits.pop()
var store = bits.join('.')
return this.get('stores.' + store).execute(...args)
}
}
class NavStore extends Store {
actions = {
async addOrEditNav({item, type}) {
// parent would also should not even have navigation
// *this class* should be what parent has for navigation
var site = this.parent.site
item = ObjChain
.from(item)
.remapKeys({
id: 'url',
url: 'external',
name: 'label',
})
item = site
.setIfNotEmpty('config.navigation', [])
.findOrAdd('config.navigation', item)
item
.when(type === 'content', () => item.set('metadata.hasPage', true))
this
.exec('saveItemMetaData', item, [site.repo], true)
.exec('saveSite', this.site)
.emit('updated')
}
}