@dazn/kopytko-framework 2.1.4 → 2.1.5

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.4",
3
+ "version": "2.1.5",
4
4
  "description": "A modern Roku's Brightscript framework",
5
5
  "keywords": [
6
6
  "brightscript",
@@ -9,6 +9,7 @@
9
9
  <field id="renderedUrl" type="string" />
10
10
  <field id="routeConfig" type="assocarray" />
11
11
  <field id="shouldSkip" type="boolean" />
12
+ <field id="skipInHistory" type="boolean" />
12
13
  <field id="virtualPath" type="string" />
13
14
  </interface>
14
15
  </component>
@@ -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 = CreateObject("roSGNode", "ActivatedRoute")
11
+ m.top.activatedRoute = _createRoute()
12
12
 
13
13
  m._history = []
14
14
  end sub
15
15
 
16
- sub navigate(data as Object)
17
- url = buildUrl(data.path, data.params)
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
- if (data.skipInHistory = Invalid OR (NOT data.skipInHistory))
20
+ isBackJourney = getProperty(navigateData, "isBackJourney", false)
21
+
22
+ if (NOT getProperty(navigateData, "skipInHistory", false))
21
23
  _updateHistory()
22
24
  end if
23
25
 
24
- if (NOT m.top.activatedRoute.shouldSkip)
25
- m.top.previousRoute = NodeUtils().cloneNode(m.top.activatedRoute)
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 = data.path
29
- m.top.activatedRoute.params = ternary(data.params <> Invalid, data.params, {})
30
- m.top.activatedRoute.backJourneyData = data.backJourneyData
31
- m.top.activatedRoute.isBackJourney = getProperty(data, "isBackJourney", false)
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(data = {} as Object) as Boolean
38
- previousLocation = m._history.pop()
39
- if (previousLocation = Invalid)
40
- return false
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
- previousLocation.skipInHistory = true
44
- previousLocation.isBackJourney = true
45
- navigate(previousLocation)
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, params: {} })
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(_createHistoryItem(m.top.activatedRoute))
67
+ m._history.push(NodeUtils().cloneNode(m.top.activatedRoute))
64
68
  end sub
65
69
 
66
- function _createHistoryItem(route as Object) as Object
67
- return {
68
- path: route.path,
69
- params: route.params,
70
- backJourneyData: route.backJourneyData,
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