Comments (6)
OK I read through the wiki docs and added code below and its working now.. Can you let me know if its correct way to implement companion method :
object Counter {
def apply () = {
val ctor = getTypedConstructor(js.constructorOf[Counter],classOf[Counter])
createElementNoProps(ctor)
}
}
from sri.
sorry for long delay , i believe you don't need this any more! , anyway yes you're right get the ctor and pass it element factory methods. now sri has better factory methods to create elements, check out
https://github.com/chandu0101/sri/blob/master/core/src/main/scala/sri/core/ElementFactory.scala#L66
In your example
case class Props(initialCount: Int = 0)
case class State(count: Int = 0, showBorder: Boolean = true)
@ScalaJSDefined
class Counter extends ReactComponent[Props,State] {
def border = {
val borderStl = if(state.showBorder) "dashed" else "dotted"
style(borderWidth := 1, borderStyle := borderStl , padding := 5)
}
initialState(State())
def render() = {
TouchableWithoutFeedback(style = border)(
///iew(onClick = tick _)(s"Clicks: ${state.count}")
View(style = styles.container)(
View(style = border)(
Text(style = styles.text2)("Dashed border style")
)
)
)
}
def tick(): Unit = {
setState(state.copy(count = state.count + 1, showBorder = (!showBorder)))
}
}
object Counter {
def apply() = makeElement[Component]
}
you can find more examples in web-examples/mobile-examples module. :)
from sri.
@chandu0101 with the new factory there's no need for the singleton and
apply methods, you can have a top-level class called Counter and use
makeElement at the call site
On Tue, Nov 8, 2016, 5:21 AM Chandra Sekhar Kode [email protected]
wrote:
@geek29 https://github.com/geek29
sorry for long delay , i believe you don't this any more! , anyway yes
you're right get the ctor and pass it element factory methods. now sri has
better factory methods to create elements, check outhttps://github.com/chandu0101/sri/blob/master/core/src/main/scala/sri/core/ElementFactory.scala#L66
In your example
object Counter {
@ScalaJSDefinedclass Component extends ReactComponent[Props,State] {def border = {
val borderStl = if(state.showBorder) "dashed" else "dotted"
style(borderWidth := 1, borderStyle := borderStl , padding := 5)
}initialState(State())
def render() = {
TouchableWithoutFeedback(style = border)(
///iew(onClick = tick _)(s"Clicks: ${state.count}")
View(style = styles.container)(
View(style = border)(
Text(style = styles.text2)("Dashed border style")
)
)
)
}def tick(): Unit = {
setState(state.copy(count = state.count + 1, showBorder = (!showBorder)))
}}case class Props(initialCount: Int = 0)case class State(count: Int = 0, showBorder: Boolean = true
)
def apply() = makeElementComponent
}—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#47 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAGAUBWxDQi81C5TH_Rbj3rbb-DDQY1mks5q8E0VgaJpZM4KFrWl
.
from sri.
there's no need for the singleton and
apply methods
yeah, but its more readable with singletons isn't it ?
makeElement[Counter] vs Counter()
makeElementNoPropsWithChildren[Counter]()(children) vs Counter(children)
from sri.
First of all, that's a choice users should make.
But if you want to encourage it, it would be more idiomatic to have top
level companions.
On Wed, Nov 9, 2016, 3:31 PM Chandra Sekhar Kode [email protected]
wrote:
there's no need for the singleton and
apply methodsyeah, but its more readable with singletons isn't it ?
makeElement[Counter] vs Counter()
makeElementNoPropsWithChildrenCounter(children) vs Counter(children)
—
You are receiving this because you commented.Reply to this email directly, view it on GitHub
#47 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAGAUHsUresB70ZBYKj9FkJfgXpTPKKaks5q8i2PgaJpZM4KFrWl
.
from sri.
First of all, that's a choice users should make.
agree
But if you want to encourage it, it would be more idiomatic to have top
level companions
i feel like naming Component
is more relevant in React
context!
_Edit:_ yeah i am wrong Component
extends ReactComponent
doesn't make much sense!, i'll update the documentation thank you :)
_Edit2:_ hmm nah, when Component has Props/State/styles/etc , defining them in companion object and importing them to use inside class looks little odd! ,I still believe having a singleton is best option!. anyway its matter of style users can choose whatever they want :)
from sri.
Related Issues (20)
- TimeoutError on building mobile example HOT 2
- Compatibility problem with React Native 0.26 HOT 4
- update to react-native 0.27 HOT 2
- move relay to different repo! HOT 1
- Eliminate getTypedConstructor boilerplate HOT 1
- Runtime error on assign a value to an input in a component HOT 4
- project name space HOT 5
- prepare for 0.6.0 release HOT 1
- Scalafmt HOT 1
- move to new organization scalajs-react-interface HOT 11
- rework on DOM(html,svg) tags HOT 18
- rework on third party components HOT 3
- rework on Web Inline Styles HOT 1
- sri.core.InternalReactComponent needs to be imported from module 'react' HOT 3
- How to use sri 0.7 mobile with react-native-web? HOT 4
- Using a third party component HOT 5
- remove sComponentX overrides from RectComponent HOT 4
- Modal component crashes on IOS 10.2 (iPhone 5)
- react-native-windows? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sri.