_withContext()
This commit is contained in:
parent
fc739d1283
commit
29bdfb2d90
2 changed files with 17 additions and 0 deletions
|
|
@ -312,6 +312,10 @@ class Pattern {
|
||||||
return this._withEvent(event => event.setContext(context))
|
return this._withEvent(event => event.setContext(context))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_withContext(func) {
|
||||||
|
return this._withEvent(event => event.setContext(func(event.context)))
|
||||||
|
}
|
||||||
|
|
||||||
withLocation(location) {
|
withLocation(location) {
|
||||||
return this.fmap(value => {
|
return this.fmap(value => {
|
||||||
value = typeof value === 'object' && !Array.isArray(value) ? value : { value };
|
value = typeof value === 'object' && !Array.isArray(value) ? value : { value };
|
||||||
|
|
|
||||||
|
|
@ -353,6 +353,19 @@ describe('Pattern', function() {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
describe('_withContext()', () => {
|
||||||
|
it('Can update the event context', () => {
|
||||||
|
assert.deepStrictEqual(
|
||||||
|
pure("a")._setContext([[[0,1],[1,2]]])._withContext(c => [...c,[[3,4],[3,4]]]).firstCycle,
|
||||||
|
[hap(ts(0,1),
|
||||||
|
ts(0,1),
|
||||||
|
"a",
|
||||||
|
[[[0,1],[1,2]],[[3,4],[3,4]]]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
describe("apply", () => {
|
describe("apply", () => {
|
||||||
it('Can apply a function', () => {
|
it('Can apply a function', () => {
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue