Skip to content

Commit

Permalink
Merge pull request #380 from georgejecook/view-api-improvements
Browse files Browse the repository at this point in the history
View api improvements
  • Loading branch information
georgejecook authored May 20, 2023
2 parents da521a0 + 807a53e commit c614f30
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 9 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

## [0.65.3](https://github.com/georgejecook/maestro-roku/compare/0.65.2...0.65.3)
## [0.65.4](https://github.com/georgejecook/maestro-roku/compare/0.65.3...0.65.4)

### Merged

- Fix/delayed task manager does not cancel tasks [`#376`](https://github.com/georgejecook/maestro-roku/pull/376)

### Commits

- fixes issues that prevented delayed task manager from removing a pending task [`a4b604e`](https://github.com/georgejecook/maestro-roku/commit/a4b604e9c139608399c13d42cd572ebb5d17b420)
- bump [`dad3a84`](https://github.com/georgejecook/maestro-roku/commit/dad3a843e5a01b7e6540b2bad79cb4c93d2016b6)

## [0.65.3](https://github.com/georgejecook/maestro-roku/compare/0.65.2...0.65.3) - 2023-05-11

### Merged

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ try {
if (filePath.endsWith('Task.xml')) {

let text = fs.readFileSync(filePath, 'utf8');
let r = /\/roku_modules\/undefined/gim;
let r = /\/roku_modules\/rokucommunity_bslib/gim;
text = text.replace(r, '/roku_modules/maestro');
fs.writeFileSync(filePath, text);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maestro-roku",
"version": "0.65.3",
"version": "0.65.4",
"description": "A development platform for building roku channels in brighterscript",
"directories": {
"doc": "docs"
Expand Down
6 changes: 5 additions & 1 deletion src/source/core/BaseClass.bs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ namespace mc
return mc.createSGNode(nodeType, parent, id, args, callInitialize, mTarget)
end function

function createFragment(fragmentJson as dynamic, targetNode = invalid as mc.types.node, dataBindingContext = invalid as dynamic, assignViewsToM = false as boolean)
return mv.createFragment(fragmentJson, targetNode, dataBindingContext, assignViewsToM)
end function

protected function createViewsFromStyleJson(childrenJson as mc.types.array, targetNode = invalid as mc.types.node, assignViewsToM = true as boolean, mTarget = invalid as mc.types.assocarray)
if mTarget = invalid
mTarget = m
Expand All @@ -81,7 +85,7 @@ namespace mc
end if
'FIXME - maestro-bsc needs to understand overloaded namespaces
'bs:disable-next-line
mv.createViewsFromStyleJson(childrenJson, targetNode, assignViewsToM, mTarget, true)
return mv.createViewsFromStyleJson(childrenJson, targetNode, assignViewsToM, mTarget, true)
end function

protected function updateViewsWithStyleJson(json as dynamic, mTarget = invalid as mc.types.assocarray)
Expand Down
2 changes: 1 addition & 1 deletion src/source/ml/cells/BaseCell.bs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace ml
end if
'FIXME - maestro-bsc needs to understand overloaded namespaces
'bs:disable-next-line
mv.createViewsFromStyleJson(childrenJson, targetNode, assignViewsToM, mTarget)
return mv.createViewsFromStyleJson(childrenJson, targetNode, assignViewsToM, mTarget)
end function

protected function updateViewsWithStyleJson(json as dynamic, mTarget = invalid as mc.types.assocarray)
Expand Down
2 changes: 1 addition & 1 deletion src/source/mx/BaseViewModel.bs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ namespace mx
end if
'FIXME - maestro-bsc needs to understand overloaded namespaces
'bs:disable-next-line
mv.createViewsFromStyleJson(childrenJson, targetNode, assignViewsToM, mTarget)
return mv.createViewsFromStyleJson(childrenJson, targetNode, assignViewsToM, mTarget)
end function

protected function updateViewsWithStyleJson(json as dynamic, mTarget = invalid as mc.types.assocarray)
Expand Down
6 changes: 5 additions & 1 deletion src/source/view/BaseCell.bs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,17 @@ namespace mv.cells
protected function _createView()
end function

function createFragment(fragmentJson as dynamic, targetNode = invalid as mc.types.node, dataBindingContext = invalid as dynamic, assignViewsToM = false as boolean)
return mv.createFragment(fragmentJson, targetNode, dataBindingContext, assignViewsToM)
end function

protected function createViewsFromStyleJson(childrenJson as mc.types.array, targetNode = invalid as mc.types.node, assignViewsToM = true as boolean, mTarget = invalid as mc.types.assocarray)
if mTarget = invalid
mTarget = m
end if
'FIXME - maestro-bsc needs to understand overloaded namespaces
'bs:disable-next-line
mv.createViewsFromStyleJson(childrenJson, targetNode, assignViewsToM, mTarget)
return mv.createViewsFromStyleJson(childrenJson, targetNode, assignViewsToM, mTarget)
end function

protected function updateViewsWithStyleJson(json as dynamic, mTarget = invalid as mc.types.assocarray)
Expand Down
94 changes: 92 additions & 2 deletions src/source/view/ViewUtils.bs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,98 @@ namespace mv
end if
end function

function createViewsFromStyleJson(childrenJson as mc.types.array, targetNode = invalid as mc.types.node, assignViewsToM = true as boolean, mTarget = invalid as mc.types.assocarray, updateDataMappedIds = false as boolean)
function createFragment(fragmentJson as dynamic, targetNode = invalid as mc.types.node, dataBindingContext = invalid as dynamic, assignViewsToM = false as boolean)
mTarget = m
if targetNode = invalid
targetNode = m.top
end if
firstView = invalid

if not mc.isArray(fragmentJson) and mc.isAACompatible(fragmentJson)
fragmentJson = [fragmentJson]
end if

if mc.isArray(fragmentJson)
if type(targetNode) = "roSGNode"
for i = 0 to fragmentJson.count() - 1
nodeJson = fragmentJson[i]

nodeType = nodeJson._type
if nodeType <> invalid
children = nodeJson._children
id = nodeJson.id
_type = nodeJson._type
_children = nodeJson._children
_initializeAfterCreatingChildren = nodeJson._initializeAfterCreatingChildren = true
nodeJson.delete("id")
nodeJson.delete("_type")
nodeJson.delete("_children")
if dataBindingContext <> invalid
bindingFields = {}
for each field in nodeJson
value = nodeJson[field]
if mc.isString(value) and value.instr("${") = 0
bindingFields[field] = value
if value.instr("[") <> -1
value = value.replace("[", ".")
value = value.replace("]", "")
end if
nodeJson[field] = mc.getPath(dataBindingContext, value.mid(2, len(value) - 3))
end if
end for
end if
view = mc.createSGNode(nodeType, targetNode, id, nodeJson, not _initializeAfterCreatingChildren, mTarget)
nodeJson.id = id
nodeJson._type = _type
nodeJson._children = _children
'bs:disable-next-line
if dataBindingContext <> invalid and bindingFields.count() > 0
'bs:disable-next-line
nodeJson.append(bindingFields)
end if
if view <> invalid
if firstView = invalid
firstView = view
end if

if children <> invalid
mv.createFragment(children, view, dataBindingContext, assignViewsToM)
end if
if assignViewsToM and id <> invalid
if mTarget[id] <> invalid
mc.private.logWarn("CREATE VIEW FROM STYLE JSON: Target view already had a view set for id", id)
end if
mTarget[id] = view
end if
else
mc.private.logError("CREATE VIEW FROM STYLE JSON: Could not create view ", id, "with type", nodeType)
end if
if _initializeAfterCreatingChildren
view@._initialize()
end if
else
mc.private.logError("CREATE VIEW FROM STYLE JSON: Could not create view ", nodeJson.id, "no _type specified")
end if
end for
else
mc.private.logError("CREATE VIEW FROM STYLE JSON: Could not create views from style Json: Target node was invalid")
end if
else
mc.private.logError("CREATE VIEW FROM STYLE JSON: Could not create view in targetNode", mc.dv(targetNode), "json was invalid")
end if

return firstView
end function

function createViewsFromStyleJson(childrenJson as mc.types.array, targetNode = invalid as mc.types.node, assignViewsToM = true as boolean, mTarget = invalid as mc.types.assocarray, updateDataMappedIds = false as boolean, dataBindingContext = invalid as dynamic)
if mTarget = invalid
mTarget = m
end if
if targetNode = invalid
targetNode = m.top
end if
firstView = invalid

'TODO - convert this to use update api, for speed.
if mc.isArray(childrenJson)
if type(targetNode) = "roSGNode"
Expand All @@ -83,6 +168,9 @@ namespace mv
nodeJson._type = _type
nodeJson._children = _children
if view <> invalid
if firstView = invalid
firstView = view
end if
if _dataMap <> invalid
mc.setOrAddNodeField(view, "_dataMap", _dataMap)
if updateDataMappedIds
Expand All @@ -93,7 +181,7 @@ namespace mv
end if
end if
if children <> invalid
mv.createViewsFromStyleJson(children, view, assignViewsToM, mTarget, updateDataMappedIds)
mv.createViewsFromStyleJson(children, view, assignViewsToM, mTarget, updateDataMappedIds, dataBindingContext)
end if
if assignViewsToM and id <> invalid
if mTarget[id] <> invalid
Expand All @@ -117,6 +205,8 @@ namespace mv
else
mc.private.logError("CREATE VIEW FROM STYLE JSON: Could not create view in targetNode", mc.dv(targetNode), "json was invalid")
end if

return firstView
end function

' update views, which have fields mapped to the node ids with json of the form of:
Expand Down
Loading

0 comments on commit c614f30

Please sign in to comment.