@dazn/kopytko-framework 1.3.2 → 1.3.3
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/components/store/Store.facade.brs +15 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.3.3](https://github.com/getndazn/kopytko-framework/compare/v1.3.2...v1.3.3) (2022-12-09)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* subscriptions remove own entries during iteration ([#36](https://github.com/getndazn/kopytko-framework/issues/36)) ([f67b6bd](https://github.com/getndazn/kopytko-framework/commit/f67b6bd5b209bb4ef2aa830b830162ee308a41ce))
|
|
7
|
+
|
|
1
8
|
## [1.3.2](https://github.com/getndazn/kopytko-framework/compare/v1.3.1...v1.3.2) (2022-09-01)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
' @import /components/getType.brs from @dazn/kopytko-utils
|
|
2
|
+
' @import /components/uuid.brs from @dazn/kopytko-utils
|
|
2
3
|
' @import /components/utils/KopytkoGlobalNode.brs
|
|
3
4
|
function StoreFacade() as Object
|
|
4
5
|
if (m._store <> Invalid)
|
|
@@ -15,7 +16,7 @@ function StoreFacade() as Object
|
|
|
15
16
|
prototype = {}
|
|
16
17
|
|
|
17
18
|
prototype._store = _global.store
|
|
18
|
-
prototype._subscriptions =
|
|
19
|
+
prototype._subscriptions = {}
|
|
19
20
|
|
|
20
21
|
prototype.updateNode = sub (key as String, value as Dynamic)
|
|
21
22
|
data = m.get(key)
|
|
@@ -94,20 +95,20 @@ function StoreFacade() as Object
|
|
|
94
95
|
|
|
95
96
|
prototype.subscribeOnce = sub (key as String, callback as Function)
|
|
96
97
|
m._handleSubscriber(key)
|
|
97
|
-
m._subscriptions.
|
|
98
|
+
m._subscriptions[m._getRandomizedKey(key)] = { key: key, callback: [callback], once: true }
|
|
98
99
|
end sub
|
|
99
100
|
|
|
100
101
|
prototype.subscribe = sub (key as String, callback as Function)
|
|
101
102
|
m._handleSubscriber(key)
|
|
102
|
-
m._subscriptions.
|
|
103
|
+
m._subscriptions[m._getRandomizedKey(key)] = { key: key, callback: [callback], once: false }
|
|
103
104
|
end sub
|
|
104
105
|
|
|
105
106
|
prototype.unsubscribe = sub (key as String, callback as Function)
|
|
106
|
-
for
|
|
107
|
-
listener = m._subscriptions[
|
|
107
|
+
for each subscriptionKey in m._subscriptions
|
|
108
|
+
listener = m._subscriptions[subscriptionKey]
|
|
108
109
|
|
|
109
110
|
if (listener <> Invalid AND listener.key = key AND listener.callback[0] = callback)
|
|
110
|
-
m._subscriptions.delete(
|
|
111
|
+
m._subscriptions.delete(subscriptionKey)
|
|
111
112
|
end if
|
|
112
113
|
end for
|
|
113
114
|
end sub
|
|
@@ -139,14 +140,14 @@ function StoreFacade() as Object
|
|
|
139
140
|
prototype._notify = sub (key as String, data as Object)
|
|
140
141
|
value = data.value
|
|
141
142
|
|
|
142
|
-
for
|
|
143
|
-
listener = m._subscriptions[
|
|
143
|
+
for each subscriptionKey in m._subscriptions
|
|
144
|
+
listener = m._subscriptions[subscriptionKey]
|
|
144
145
|
|
|
145
|
-
if (listener.key = key)
|
|
146
|
+
if (listener <> Invalid AND listener.key = key)
|
|
146
147
|
listener.callback[0](value)
|
|
147
148
|
|
|
148
149
|
if (listener.once)
|
|
149
|
-
m._subscriptions.delete(
|
|
150
|
+
m._subscriptions.delete(subscriptionKey)
|
|
150
151
|
end if
|
|
151
152
|
end if
|
|
152
153
|
end for
|
|
@@ -164,6 +165,10 @@ function StoreFacade() as Object
|
|
|
164
165
|
end if
|
|
165
166
|
end sub
|
|
166
167
|
|
|
168
|
+
prototype._getRandomizedKey = function (key as String) as String
|
|
169
|
+
return key + "_" + uuid()
|
|
170
|
+
end function
|
|
171
|
+
|
|
167
172
|
m._store = prototype
|
|
168
173
|
|
|
169
174
|
return m._store
|