@dazn/kopytko-framework 2.1.5 → 3.1.0

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": "2.1.5",
3
+ "version": "3.1.0",
4
4
  "description": "A modern Roku's Brightscript framework",
5
5
  "keywords": [
6
6
  "brightscript",
@@ -1,5 +1,6 @@
1
1
  ' @import /components/buildUrl.brs from @dazn/kopytko-utils
2
2
  ' @import /components/getProperty.brs from @dazn/kopytko-utils
3
+ ' @import /components/getType.brs from @dazn/kopytko-utils
3
4
  ' @import /components/rokuComponents/Timespan.brs from @dazn/kopytko-utils
4
5
  ' @import /components/rokuComponents/UrlTransfer.brs from @dazn/kopytko-utils
5
6
  ' @import /components/ternary.brs from @dazn/kopytko-utils
@@ -13,6 +14,7 @@
13
14
  ' @property {Object} headers
14
15
  ' @property {Integer} timeout
15
16
  ' @property {Object} body
17
+ ' @property {String} bodyString
16
18
 
17
19
  ' Request logic.
18
20
  ' @class
@@ -51,7 +53,7 @@ function HttpRequest(options as Object, httpInterceptors = [] as Object) as Obje
51
53
  m._urlTransfer.initClientCertificates()
52
54
  end if
53
55
 
54
- if (Type(m._options.headers) = "roAssociativeArray")
56
+ if (getType(m._options.headers) = "roAssociativeArray")
55
57
  m._headers.append(m._options.headers)
56
58
  end if
57
59
 
@@ -79,6 +81,8 @@ function HttpRequest(options as Object, httpInterceptors = [] as Object) as Obje
79
81
 
80
82
  if (m._options.body <> Invalid)
81
83
  body = FormatJSON(m._options.body)
84
+ else if (getType(m._options.bodyString) = "roString")
85
+ body = m._options.bodyString
82
86
  end if
83
87
 
84
88
  m._urlTransfer.asyncPostFromString(body)
@@ -1,7 +1,10 @@
1
+ ' @import /components/functionCall.brs from @dazn/kopytko-utils
2
+
1
3
  sub init()
2
4
  m.state = {}
3
5
  m.elementToFocus = Invalid
4
6
 
7
+ m._enabledErrorCatching = _isComponentDidCatchEnabled()
5
8
  m._isInitialized = false
6
9
  m._previousProps = {}
7
10
  m._previousState = {}
@@ -21,7 +24,8 @@ sub initKopytko(dynamicProps = {} as Object, componentsMapping = {} as Object)
21
24
  m.top.observeFieldScoped("focusedChild", "focusDidChange")
22
25
  m.top.update(dynamicProps)
23
26
 
24
- constructor()
27
+ _methodCall(constructor, "constructor")
28
+
25
29
  m._previousState = _cloneObject(m.state) ' required because of setting default state in constructor()
26
30
 
27
31
  _mountComponent()
@@ -32,7 +36,7 @@ end sub
32
36
  sub destroyKopytko(data = {} as Object)
33
37
  if (NOT m._isInitialized) then return
34
38
 
35
- componentWillUnmount()
39
+ _methodCall(componentWillUnmount, "componentWillUnmount")
36
40
 
37
41
  if (m["$$eventBus"] <> Invalid)
38
42
  m["$$eventBus"].clear()
@@ -41,7 +45,8 @@ sub destroyKopytko(data = {} as Object)
41
45
  m.state = {}
42
46
  m._previousState = {}
43
47
  m.top.unobserveFieldScoped("focusedChild")
44
- m._kopytkoUpdater.destroy()
48
+
49
+ _methodCall(m._kopytkoUpdater.destroy, "destroyKopytko", [], m._kopytkoUpdater)
45
50
 
46
51
  _clearDOM()
47
52
 
@@ -73,15 +78,15 @@ sub focusDidChange(event as Object)
73
78
  end sub
74
79
 
75
80
  sub setState(partialState as Object, callback = Invalid as Dynamic)
76
- m._kopytkoUpdater.enqueueStateUpdate(partialState, callback)
81
+ _methodCall(m._kopytkoUpdater.enqueueStateUpdate, "setState", [partialState, callback], m._kopytkoUpdater)
77
82
  end sub
78
83
 
79
84
  sub forceUpdate()
80
- m._kopytkoUpdater.forceStateUpdate()
85
+ _methodCall(m._kopytkoUpdater.forceStateUpdate, "forceUpdate", [], m._kopytkoUpdater)
81
86
  end sub
82
87
 
83
88
  sub enqueueUpdate()
84
- m._kopytkoUpdater.enqueueStateUpdate()
89
+ _methodCall(m._kopytkoUpdater.enqueueStateUpdate, "enqueueUpdate", [], m._kopytkoUpdater)
85
90
  end sub
86
91
 
87
92
  sub updateProps(props = {} as Object)
@@ -92,10 +97,10 @@ end sub
92
97
 
93
98
  sub _mountComponent()
94
99
  m._virtualDOM = render()
95
- m._kopytkoDOM.renderElement(m._virtualDOM, m.top)
96
100
 
97
- m._kopytkoUpdater.setComponentMounted(m.state)
98
- componentDidMount()
101
+ _methodCall(m._kopytkoDOM.renderElement, "renderElement", [m._virtualDOM, m.top], m._kopytkoDOM)
102
+ _methodCall(m._kopytkoUpdater.setComponentMounted, "setComponentMounted", [m.state], m._kopytkoUpdater)
103
+ _methodCall(componentDidMount, "componentDidMount")
99
104
  end sub
100
105
 
101
106
  sub _onStateUpdated()
@@ -114,7 +119,8 @@ sub _updateDOM()
114
119
  m.top.setFocus(true)
115
120
  end if
116
121
 
117
- componentDidUpdate(m._previousProps, m._previousState)
122
+ _methodCall(componentDidUpdate, "componentDidUpdate", [m._previousProps, m._previousState])
123
+
118
124
  m._previousState = _cloneObject(m.state)
119
125
  end sub
120
126
 
@@ -131,3 +137,37 @@ function _cloneObject(obj as Object) as Object
131
137
 
132
138
  return newObj
133
139
  end function
140
+
141
+ function _isComponentDidCatchEnabled() as Boolean
142
+ isComponentDidCatchEnabled = false
143
+
144
+ #if enableKopytkoComponentDidCatch
145
+ isComponentDidCatchEnabled = true
146
+ #end if
147
+
148
+ return isComponentDidCatchEnabled AND Type(componentDidCatch) <> "<uninitialized>"
149
+ end function
150
+
151
+ sub _methodCall(func as Function, methodName as String, args = [] as Object, context = Invalid as Object)
152
+ if (m._enabledErrorCatching)
153
+ try
154
+ functionCall(func, args, context)
155
+ catch error
156
+ _throw(error, methodName)
157
+ end try
158
+
159
+ return
160
+ end if
161
+
162
+ functionCall(func, args, context)
163
+ end sub
164
+
165
+ sub _throw(error as Object, failingComponentMethod as String)
166
+ componentDidCatch(error, {
167
+ componentMethod: failingComponentMethod,
168
+ componentName: m.top.subtype(),
169
+ componentProps: m.top.getFields(),
170
+ componentState: m.state,
171
+ componentVirtualDOM: m._virtualDOM,
172
+ })
173
+ end sub