feat(core): Make top-level store methods available through shorthand
This commit is contained in:
parent
411f617ffe
commit
ef4a70c8f3
2 changed files with 35 additions and 0 deletions
|
@ -197,6 +197,13 @@ Part.prototype.shorthand = function () {
|
|||
addCut: this.addCut,
|
||||
removeCut: this.removeCut,
|
||||
}
|
||||
// Add top-level store methods and add a part name parameter
|
||||
const partName = this.name
|
||||
for (const [key, method] of Object.entries(this.context.store)) {
|
||||
if (typeof method === 'function') shorthand[key] = function(...args) {
|
||||
return method(partName, ...args)
|
||||
}
|
||||
}
|
||||
|
||||
// We'll need this
|
||||
let self = this
|
||||
|
|
|
@ -65,5 +65,33 @@ describe('Store', () => {
|
|||
expect(pattern.store.get("test.message.warning")).to.equal("hello warning")
|
||||
expect(pattern.store.get("test.message.info")).to.equal("hello info")
|
||||
});
|
||||
|
||||
it("Should make top-level plugin methods available via shorthand", () => {
|
||||
const plugin = {
|
||||
name: 'test',
|
||||
version: 1,
|
||||
store: [
|
||||
['methodA', function(store, name, msg) {
|
||||
store.set(['test', name, 'a'], msg)
|
||||
}],
|
||||
['methodB', function(store, name, msg) {
|
||||
store.set(['test', name, 'b'], msg)
|
||||
}],
|
||||
]
|
||||
}
|
||||
const part = {
|
||||
name: 'example_part',
|
||||
draft: part => {
|
||||
const { methodA, methodB } = part.shorthand()
|
||||
methodA('hello A')
|
||||
methodB('hello B')
|
||||
}
|
||||
}
|
||||
const Test = new Design({plugins: [plugin], parts: [ part ]})
|
||||
const pattern = new Test()
|
||||
pattern.draft()
|
||||
expect(pattern.store.get("test.example_part.a")).to.equal("hello A")
|
||||
expect(pattern.store.get("test.example_part.b")).to.equal("hello B")
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue