getndazn / kopytko-framework

A modern Roku's Brightscript framework based on JS world's solutions
MIT License
19 stars 6 forks source link

feat: store's subscribe callback accepts a context #40

Closed bchelkowski closed 1 year ago

bchelkowski commented 1 year ago

What did you implement:

Closes #18

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:

Is this ready for review?: YES Is it a breaking change?: NO

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 1.4.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: