@dazn/kopytko-framework 2.1.4 → 3.0.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,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
|
-
|
|
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
|
|
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.
|
|
98
|
-
|
|
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
|
|
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
|
|
@@ -1,48 +1,48 @@
|
|
|
1
1
|
' @import /components/buildUrl.brs from @dazn/kopytko-utils
|
|
2
2
|
' @import /components/getProperty.brs from @dazn/kopytko-utils
|
|
3
3
|
' @import /components/NodeUtils.brs from @dazn/kopytko-utils
|
|
4
|
-
' @import /components/ternary.brs from @dazn/kopytko-utils
|
|
5
4
|
' @import /components/utils/KopytkoGlobalNode.brs
|
|
5
|
+
|
|
6
6
|
sub init()
|
|
7
7
|
_global = KopytkoGlobalNode()
|
|
8
8
|
_global.addFields({
|
|
9
9
|
router: m.top,
|
|
10
10
|
})
|
|
11
|
-
m.top.activatedRoute =
|
|
11
|
+
m.top.activatedRoute = _createRoute()
|
|
12
12
|
|
|
13
13
|
m._history = []
|
|
14
14
|
end sub
|
|
15
15
|
|
|
16
|
-
sub navigate(
|
|
17
|
-
url = buildUrl(
|
|
16
|
+
sub navigate(navigateData as Object)
|
|
17
|
+
url = buildUrl(navigateData.path, navigateData.params)
|
|
18
18
|
if (url = m.top.url) then return ' Avoid doubling url
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
isBackJourney = getProperty(navigateData, "isBackJourney", false)
|
|
21
|
+
|
|
22
|
+
if (NOT getProperty(navigateData, "skipInHistory", false))
|
|
21
23
|
_updateHistory()
|
|
22
24
|
end if
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
end if
|
|
26
|
+
' Needs to be set before activatedRoute as _getPreviousRoute uses the previous value of activatedRoute.
|
|
27
|
+
m.top.previousRoute = _getPreviousRoute(isBackJourney)
|
|
27
28
|
|
|
28
|
-
m.top.activatedRoute.path =
|
|
29
|
-
m.top.activatedRoute.params =
|
|
30
|
-
m.top.activatedRoute.backJourneyData =
|
|
31
|
-
m.top.activatedRoute.isBackJourney =
|
|
29
|
+
m.top.activatedRoute.path = getProperty(navigateData, "path", "")
|
|
30
|
+
m.top.activatedRoute.params = getProperty(navigateData, "params", {})
|
|
31
|
+
m.top.activatedRoute.backJourneyData = navigateData.backJourneyData
|
|
32
|
+
m.top.activatedRoute.isBackJourney = isBackJourney
|
|
32
33
|
m.top.activatedRoute.shouldSkip = false
|
|
33
|
-
m.top.activatedRoute.virtualPath = ""
|
|
34
|
+
m.top.activatedRoute.virtualPath = getProperty(navigateData, "virtualPath", "")
|
|
34
35
|
m.top.url = url
|
|
35
36
|
end sub
|
|
36
37
|
|
|
37
|
-
function back(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
end if
|
|
38
|
+
function back(_backData = {} as Object) as Boolean
|
|
39
|
+
previousRoute = m._history.pop()
|
|
40
|
+
|
|
41
|
+
if (previousRoute = Invalid) then return false
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
navigate(
|
|
43
|
+
previousRoute.skipInHistory = true
|
|
44
|
+
previousRoute.isBackJourney = true
|
|
45
|
+
navigate(previousRoute)
|
|
46
46
|
|
|
47
47
|
return true
|
|
48
48
|
end function
|
|
@@ -51,22 +51,25 @@ sub resetHistory(rootPath = "" as String)
|
|
|
51
51
|
m._history = []
|
|
52
52
|
|
|
53
53
|
if (rootPath <> "")
|
|
54
|
-
m._history.push({ path: rootPath
|
|
54
|
+
m._history.push(_createRoute({ path: rootPath }))
|
|
55
55
|
end if
|
|
56
56
|
end sub
|
|
57
57
|
|
|
58
|
+
function _getPreviousRoute(isBackJourney as Boolean) as Object
|
|
59
|
+
if (isBackJourney OR m.top.activatedRoute.shouldSkip) then return m._history.peek()
|
|
60
|
+
|
|
61
|
+
return NodeUtils().cloneNode(m.top.activatedRoute)
|
|
62
|
+
end function
|
|
63
|
+
|
|
58
64
|
sub _updateHistory()
|
|
59
|
-
if (m.top.url = "" OR m.top.activatedRoute.shouldSkip)
|
|
60
|
-
return
|
|
61
|
-
end if
|
|
65
|
+
if (m.top.url = "" OR m.top.activatedRoute.shouldSkip) then return
|
|
62
66
|
|
|
63
|
-
m._history.push(
|
|
67
|
+
m._history.push(NodeUtils().cloneNode(m.top.activatedRoute))
|
|
64
68
|
end sub
|
|
65
69
|
|
|
66
|
-
function
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
70
|
+
function _createRoute(routeData = {} as Object) as Object
|
|
71
|
+
route = CreateObject("roSGNode", "ActivatedRoute")
|
|
72
|
+
route.setFields(routeData)
|
|
73
|
+
|
|
74
|
+
return route
|
|
72
75
|
end function
|