File tree Expand file tree Collapse file tree 2 files changed +13
-13
lines changed
core/src/main/scala/io/github/shogowada/scalajs/reactjs
example/helloworld/src/main/scala/io/github/shogowada/scalajs/reactjs/example/helloworld Expand file tree Collapse file tree 2 files changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -131,19 +131,19 @@ trait VirtualDOM extends StaticTags {
131
131
}
132
132
133
133
def toReactAttributes (attributes : Iterable [Attribute [_]]): js.Dictionary [js.Any ] = {
134
- val maybeProps = attributes.find(_.name == " plainProps" )
135
- maybeProps match {
136
- case Some (propsAttr) => propsAttr.value.asInstanceOf [js.Dictionary [js.Any ]]
137
- case None =>
138
- attributes
139
- .map(attributeToReactAttribute)
140
- .toMap
141
- .toJSDictionary
134
+ val result = js.Dictionary .empty[js.Any ]
135
+ attributes.foreach { attribute =>
136
+ if (attribute.name == " plainProps" ) {
137
+ js.Object .assign(result.asInstanceOf [js.Object ], attribute.value.asInstanceOf [js.Object ])
138
+ }
139
+ else {
140
+ val name = toReactAttributeName(attribute.name)
141
+ result(name) = attributeValueToReactAttributeValue(attribute)
142
+ }
142
143
}
143
- }
144
144
145
- private def attributeToReactAttribute ( attribute : Attribute [_]) : ( String , js. Any ) =
146
- toReactAttributeName(attribute.name) -> attributeValueToReactAttributeValue(attribute)
145
+ result
146
+ }
147
147
148
148
private def attributeValueToReactAttributeValue (attribute : Attribute [_]): js.Any =
149
149
attribute match {
Original file line number Diff line number Diff line change @@ -40,11 +40,11 @@ object Main {
40
40
}
41
41
42
42
val reactClass = React .createClass[PlainJSProps , Unit ] { self =>
43
- < .div(^ .id := " hello-world" )(s " Hello , ${self.props.plain.name}! " )
43
+ < .div(^ .id := " hello-world" )(s " ${self.props.native.value} , ${self.props.plain.name}! " )
44
44
}
45
45
46
46
val mountNode = dom.document.getElementById(" mount-node" )
47
- ReactDOM .render(< (reactClass)(^ .plain := PlainJSProps (" World" ))(), mountNode)
47
+ ReactDOM .render(< (reactClass)(^ .value := " Hello " , ^ . plain := PlainJSProps (" World" ))(), mountNode)
48
48
}
49
49
50
50
renderUsingWrappedProps()
You can’t perform that action at this time.
0 commit comments