Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use JsMap wrapper (JS component) #125

Merged
merged 1 commit into from
Apr 10, 2024
Merged

Conversation

vgarciabnz
Copy link
Member

Uses Kotlin js wrappers to expose native JS Map instead of Array<Entry>.

@@ -122,7 +123,7 @@ class RuleEngineJs {
return RuleActionJs(
data = ruleAction.data,
type = ruleAction.type,
values = ruleAction.values.entries.map { e -> Entry(e.key, e.value) }.toTypedArray()
values = JsMap(ruleAction.values.entries.map { e -> tupleOf(e.key, e.value) }.toTypedArray())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
values = JsMap(ruleAction.values.entries.map { e -> tupleOf(e.key, e.value) }.toTypedArray())
values = ruleAction.values

Shouldn't work like this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are different types. The type of RuleAction.values is Map, the type of RuleActionJs.values is JsMap.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course 😬

@@ -122,7 +123,7 @@ class RuleEngineJs {
return RuleActionJs(
data = ruleAction.data,
type = ruleAction.type,
values = ruleAction.values.entries.map { e -> Entry(e.key, e.value) }.toTypedArray()
values = JsMap(ruleAction.values.entries.map { e -> tupleOf(e.key, e.value) }.toTypedArray())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course 😬

val res : MutableMap<K, V> = mutableMapOf()
map.forEach { e -> res[key(e.key)] = value(e.value) }
map.forEach { v, k -> res[key(k)] = value(v) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks backwards, I*d expect k,v, is this indeed defined like this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is v, k because it is defined like that in JS Map class and the wrapper must mimic the syntax (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach#syntax).
Actually, if I change the order it doesn't compile, it is type-safe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vgarciabnz vgarciabnz merged commit 63f89f0 into beta Apr 10, 2024
1 check passed
@vgarciabnz vgarciabnz deleted the kotlin-js-wrappers branch April 10, 2024 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants