This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implements: navigation callbacks (events); operations object and array; expressions on initial value of states. Renamed params on navigation to state. * detekt
- Loading branch information
1 parent
f2fb0f1
commit 542681a
Showing
16 changed files
with
565 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/commonMain/kotlin/br/com/zup/nimbus/core/ui/action/triggerViewEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2023 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package br.com.zup.nimbus.core.ui.action | ||
|
||
import br.com.zup.nimbus.core.ActionTriggeredEvent | ||
import br.com.zup.nimbus.core.deserialization.AnyServerDrivenData | ||
import br.com.zup.nimbus.core.ui.action.error.ActionDeserializationError | ||
|
||
internal fun triggerViewEvent(event: ActionTriggeredEvent) { | ||
val data = AnyServerDrivenData(event.action.properties) | ||
val nameOfEventToTrigger = data.get("event").asString() | ||
val valueForEventToTrigger = data.get("value").asAnyOrNull() | ||
if (data.hasError()) { | ||
throw ActionDeserializationError(event, data) | ||
} | ||
val eventToTrigger = event.scope.view.events?.find { it.name == nameOfEventToTrigger } | ||
if (eventToTrigger == null) { | ||
event.scope.nimbus.logger.error("Can't trigger view event named \"$nameOfEventToTrigger\" because the current " + | ||
"view has no such event.") | ||
} else { | ||
eventToTrigger.run(valueForEventToTrigger) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/commonMain/kotlin/br/com/zup/nimbus/core/ui/operations/object.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2023 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package br.com.zup.nimbus.core.ui.operations | ||
|
||
import br.com.zup.nimbus.core.ui.UILibrary | ||
|
||
internal fun registerObjectOperations(library: UILibrary) { | ||
library | ||
.addOperation("object") { | ||
val objectMap = mutableMapOf<String, Any?>() | ||
for (i in it.indices step 2) { | ||
objectMap[it.getOrNull(i).toString()] = it.getOrNull(i + 1) | ||
} | ||
objectMap | ||
} | ||
.addOperation("entries") { | ||
val result = it.firstOrNull()?.let { map -> | ||
if (map is Map<*, *>) map.entries.map { entry -> mapOf("key" to entry.key, "value" to entry.value) } | ||
else null | ||
} | ||
result ?: emptyList<Any>() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.