-
Notifications
You must be signed in to change notification settings - Fork 17
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
Conversation
@@ -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()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
values = JsMap(ruleAction.values.entries.map { e -> tupleOf(e.key, e.value) }.toTypedArray()) | |
values = ruleAction.values |
Shouldn't work like this?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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) } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI it is defined in this class https://github.com/JetBrains/kotlin-wrappers/blob/master/kotlin-js/src/jsMain/kotlin/js/collections/JsMap.kt
Uses Kotlin js wrappers to expose native JS Map instead of
Array<Entry>
.