@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
|
@@ -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", "
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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)
|
|
@@ -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:
|
|
13
|
+
eventBus: eventBusNode,
|
|
11
14
|
router: createNode(),
|
|
12
15
|
store: createNode(),
|
|
13
16
|
theme: createNode(),
|