The Store's subscription callback receives now passed context.
How did you implement it:
subscribe and subscribeOnce methods have now an additional optional argument - context
How can we verify it:
There are new unit tests:
it("should call callback with the given context when it is provided", function (_ts as Object) as String
' Given
context = { __spy: { contextSubscriber: { calledTimes: 0 } } }
store = StoreFacade()
' When
store.subscribe("title", contextSubscriber, context)
store.set("title", "someTitle")
store.set("title", Invalid)
' Then
return expect(context.__spy.contextSubscriber.calledTimes).toBe(2)
end function)
it("should call callback with the given context when it is provided", function (_ts as Object) as String
' Given
context = { __spy: { contextSubscriber: { calledTimes: 0 } } }
store = StoreFacade()
' When
store.subscribeOnce("title", contextSubscriber, context)
store.set("title", "someTitle")
' Then
return expect(context.__spy.contextSubscriber.calledTimes).toBe(1)
end function)
Where
sub contextSubscriber(arg1 as Dynamic, context as Object)
context.__spy.contextSubscriber.lastArg = arg1
context.__spy.contextSubscriber.calledTimes += 1
end sub
Todos:
[x] Write documentation (if required)
[x] Fix linting errors
[x] Enable "Allow edits from maintainers" for this PR
[x] Update the messages below
Is this ready for review?: YES
Is it a breaking change?: NO
What did you implement:
Closes #18
The Store's subscription callback receives now passed context.
How did you implement it:
subscribe
andsubscribeOnce
methods have now an additional optional argument - contextHow can we verify it:
There are new unit tests:
Where
Todos:
Is this ready for review?: YES Is it a breaking change?: NO