These are chat archives for ThoughtWorksInc/Binding.scala

27th
Nov 2018
Pascal Mengelt
@pme123
Nov 27 2018 07:49
@nakedcity here I always have to reference my little blog;) https://pme123.github.io/scala-adapters/development/binding-scala-redux/
Mustafa Kuscu
@mcku
Nov 27 2018 12:05
@kahliburke thanks for the idea. Here is a gist. https://gist.github.com/mcku/9c360d39dba7915391207f84d1bd0680 . Using MutationObserver, I am able to use jQuery based semantic-ui components without rewriting them in binding.scala from scratch.
Mustafa Kuscu
@mcku
Nov 27 2018 12:11
It is easy to rewrite simple ones but a complex dropdown component was an interesting and messy experiment for me.
Leonid Turnaev
@glmars
Nov 27 2018 13:37
@nakedcity why you need it? We switched from something like Redux+React to Binding.scala, because it replaces both. We are happy with frontend now!
JohnZorn
@nakedcity
Nov 27 2018 13:40
@glmars I do agree about there is not need but still I like to use some kinda mechanism where the state is centralize
I dont mind to switch to anything that does some state management I was even thinking about https://github.com/suzaku-io/diode
when it comes to redux the only that I really like of it is the dev tools which I have found very handy for following the state of the app
I was just asking what is the common practice when you work with Scala.Binding
杨博 (Yang Bo)
@Atry
Nov 27 2018 14:17
There is a DEMO that demonstrates how to build a center state tree similar to Redux https://scalafiddle.io/sf/o5fWdS3/3
Note that subview1 and subview2 accept Binding as parameters instead of raw values, in order to partially rendering subviews that when only parts of store are changed.
In the above example, there is only one Var used in the entire application.
Mustafa Kuscu
@mcku
Nov 27 2018 15:07
@nakedcity I also switched from a react+redux app to binding.scala. For keeping alignment with the old project, I am maintaining an actions.scala and a reducers.scala. I think the type safe copy (which @atry mentioned the demo) is the killer feature (would it be a bold statement to claim that it is something JS/TS world never had?) and can implement redux very easily. and you don't code on the overly-async javascript, instead scala and execution order is not an issue afaik (once upon a time I was banging my head with promise chains). Then the redux is not necessary because the state is already there in a stable manner. In JS world keeping a global state would be very unstable and would be hard to detect and reason on who modifies what. But simply you don't have such language-originated deficiencies in ScalaJs. That's a summary of my overall impression so far.
The redux middlewares have changed multiple times within the last 2 years. There was redux-thunk 2 years ago now they have some other thing (I can't remember). Now if you start you completely start with a different paradigm, and I don't expect a stable approach to develop there in the short or middle term.
JohnZorn
@nakedcity
Nov 27 2018 17:03
Thanks for all the answers but still the question is what are you guys normally using diode, raw objects? I dont care about redux
Leonid Turnaev
@glmars
Nov 27 2018 17:28
Yes. I used. Diode is the same as React (+ TypeScript :smile: ), only difference is Scala language.
Leonid Turnaev
@glmars
Nov 27 2018 18:20

@mcku

Using MutationObserver, I am able to use jQuery based semantic-ui components without rewriting them in binding.scala from scratch

Could you check something like this: https://gist.github.com/glmars/a597f7c28931a38e2e9b3262279889a9 ?
The main ideas are using Element based selector in jQuery instead of string based and initializing of control right after creation.

Leonid Turnaev
@glmars
Nov 27 2018 18:31
And if I my guess is correct you are using outdated jQuery facade (https://github.com/sjrd/scala-js-jquery)
There is new one: https://github.com/jducoeur/jquery-facade
Mustafa Kuscu
@mcku
Nov 27 2018 18:37
I agree. I should admit that I never wanted to enter the jQuery zone. Because there already existed a separate semantic-ui project called stardust, which avoids jQuery completely. It is possible to inspire from that (which i did, too) and rewrite the components, as they did for the stardust. (http://react.semantic-ui.com, and for the dropdown, https://github.com/Semantic-Org/Semantic-UI-React/blob/master/src/modules/Dropdown/Dropdown.js ) But the rewrite can be an exhaustive task.
But the problem with the jQuery part is it only answers to queries after the element is on the dom. Therefore in a binding method, the element is still not mounted on the actual dom, if i understand it correctly. Nevertheless, i did not know this before and i have tried what you have suggested some time ago, and did not work and this is the conclusion i got after inspecting at the browser debugger.
Mustafa Kuscu
@mcku
Nov 27 2018 18:44
There is also the udash jQuery facade. I was using that until i discovered that it was including a bootstrap dropdown (but later i partially realized that it was coming from udash-bootstrap), therefore removed it.
Mustafa Kuscu
@mcku
Nov 27 2018 18:51
btw, i am using udash i18n for migrating existing translations from lingui. but modified it a little bit, so that {t("hello").bind} gives the correct translation. The idea came from here: https://lingui.js.org/tutorials/react-patterns.html#id1 and i think it is good, and that idea can be ported to scalajs
i think part of the work would be to write a sbt plugin that includes a macro to preprocess the code and extract messages, (lingui js uses babel for that), and a translating function that can utilize udash's translation provider and combining that with binding.scala. the result is very efficient and readable.
but i don't have the plugin yet. just the idea and a similar concept for the plugin of scalingua (https://github.com/makkarpov/scalingua) unfortunately i could not make it work in scalajs
Mustafa Kuscu
@mcku
Nov 27 2018 19:01
for the udash translation wrapper, most of it is here https://gist.github.com/mcku/dd71065a93bf409e8688e75734fde6ce
JohnZorn
@nakedcity
Nov 27 2018 19:39
@glmars dude do you have some example of integreation with diode?