@dazn/kopytko-framework 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dazn/kopytko-framework",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "A modern Roku's Brightscript framework",
5
5
  "keywords": [
6
6
  "brightscript",
@@ -9,7 +9,7 @@ function EventBusFacade() as Object
9
9
  _global = KopytkoGlobalNode()
10
10
  if (NOT _global.hasField("eventBus"))
11
11
  _global.addFields({
12
- eventBus: CreateObject("roSGNode", "Node"),
12
+ eventBus: CreateObject("roSGNode", "EventBus"),
13
13
  })
14
14
  end if
15
15
 
@@ -36,7 +36,7 @@ function EventBusFacade() as Object
36
36
  m._eventsMap[eventName].push({ handler: handler, context: context })
37
37
 
38
38
  m._eventBus.unobserveFieldScoped(eventName)
39
- m._eventBus.observeFieldScoped(eventName, "EventBus_onEventFired")
39
+ m._eventBus.observeFieldScoped(eventName, "EventBus_onEventFired", ["$$payload"])
40
40
  end sub
41
41
 
42
42
  ' Detach subscriber for an event
@@ -69,15 +69,20 @@ function EventBusFacade() as Object
69
69
  ' @param {Object} [payload={}]
70
70
  prototype.trigger = sub (eventName as String, payload = {} as Object)
71
71
  m._ensureEventExistence(eventName)
72
- m._eventBus[eventName] = payload
72
+
73
+ ' The event payload is stored in a separate field to avoid memory leaks.
74
+ ' Payload needs to be removed from the EventBus node, and if that would
75
+ ' be stored in the AA field of a specific event, then callbacks would be
76
+ ' triggered for another time after changing the value to invalid.
77
+ m._eventBus["$$payload"] = payload
78
+ m._eventBus[eventName] = true
79
+ m._eventBus["$$payload"] = Invalid
73
80
  end sub
74
81
 
75
82
  ' @private
76
83
  prototype._ensureEventExistence = sub (eventName as String)
77
84
  if (NOT m._eventBus.hasField(eventName))
78
- fields = {}
79
- fields[eventName] = {}
80
- m._eventBus.addFields(fields)
85
+ m._eventBus.addField(eventName, "boolean", true)
81
86
  end if
82
87
  end sub
83
88
 
@@ -95,7 +100,11 @@ sub EventBus_onEventFired(event as Object)
95
100
  return
96
101
  end if
97
102
 
98
- payload = event.getData()
103
+ payload = Invalid
104
+ context = event.getInfo()
105
+ if (context <> Invalid)
106
+ payload = context["$$payload"]
107
+ end if
99
108
 
100
109
  for each callback in callbacks
101
110
  functionCall(callback.handler, [payload], callback.context)
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+
3
+ <component name="EventBus" extends="Node">
4
+ <interface>
5
+ <field id="$$payload" type="assocarray" /> <!-- prefixed with $$ to avoid name collision with dynamically added events -->
6
+ </interface>
7
+ </component>
@@ -5,9 +5,12 @@
5
5
 
6
6
  ' @returns {Mock}
7
7
  function KopytkoGlobalNode() as Object
8
+ eventBusNode = createNode()
9
+ eventBusNode.addField("$$payload", "assocarray", false)
10
+
8
11
  fields = {
9
12
  cache: createNode(),
10
- eventBus: createNode(),
13
+ eventBus: eventBusNode,
11
14
  router: createNode(),
12
15
  store: createNode(),
13
16
  theme: createNode(),