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

Using a template system, instead of inline-HTML #245

Open
aalwash opened this issue Jan 8, 2018 · 18 comments
Open

Using a template system, instead of inline-HTML #245

aalwash opened this issue Jan 8, 2018 · 18 comments

Comments

@aalwash
Copy link
Contributor

aalwash commented Jan 8, 2018

Hi,

I'm using the dashticz system now for a few weeks and it's awesome.
However, the inline-HTML in the JS code does bother me a lot.

Did you guys think about using a light template JavaScript engine?
I previously used Mustache and after that I used Ractive.js

Ractive.js is Mustache on steroids and has a lot of cool options (looping, two-way binding, partials, events, conditional sections, etc)

I think this will clean up the code a lot and make it more bug-"proof"

Of course, this a big change and a huge challenge, so this should be done in small peaces.

Check the tutorials https://ractive.js.org/tutorials/hello-world/

What do you guys think?

@aalwash
Copy link
Contributor Author

aalwash commented Jan 8, 2018

Btw, the extra advantage of seperating the "model" and the view (template), we can unit test the code.

Now it's almost impossible to unit test the code, for expected behavior, since the code is changing a lot in the DOM.
If we start separating the templates and we the code only provides a data layer to the template, then you can unit test if the data output is working as expected.
Without bothering about the template part, which is handled by RactiveJS itself.

NOTE RactiveJS != ReactJS ;)
That's a more advanced system + you need to compile that to make something work.
Could be very heavy for ARM systems.

@aiolos
Copy link
Contributor

aiolos commented Jan 8, 2018

Hi,

Good idea to make the code more unit testable. I can tell you: the code already improved a lot over the last few month. I made some huge changes in removing duplicate code and handling stuff more alike.
Quite common on a growing code base, but it is good to see how we can keep improving it.

I don't know ractive (sound like just another JS library ;)). The disadvantage from using such a framework could mean a lot of overhead, while most of the stuff also can be done in VanillaJS (splitting the logic and the html can also be done there). Using a framework can mean that performance on slower tablets gets terrible.

@aalwash
Copy link
Contributor Author

aalwash commented Jan 8, 2018

Happy to hear that a lot of changes are done the last months. I indeed already noticed some code cleanup, but still I see a lot of stuff that can be deduplicated and/or improvement.

I agree, I try to avoid more and more frameworks.
But Ractive is build on the same principles as ReactJS (which is build by Facebook and used by them). See http://reactkungfu.com/2015/10/the-difference-between-virtual-dom-and-dom/
It uses the virtual DOM (instead of the normal one) and modifies only the nodes that you're changing.
Maybe hard to believe, it can even be faster then what I see in the current. The code use .html() all the time, that's really slow and requires redrawing a lot.

Just an extra note, RactiveJS is a template engine, not a framework (like jQuery, or Angular, etc).

@aiolos
Copy link
Contributor

aiolos commented Jan 8, 2018

Oh, for sure a lot can be improved. But step by step, otherwise we break everything (which already happens sometimes).

We can give it a try of course. Let's play with it in a branch and see how it performs.

@aalwash
Copy link
Contributor Author

aalwash commented Jan 8, 2018

I totally agree, we should do it step by step.

Maybe only use it for new blocks? Or new plugins, so we can start testing it.
Let me see when I can fix some time for this so I can give it a kick-off.

@robgeerts
Copy link
Collaborator

Good idea!
We could also start with something basic like the HTML in coins.js-file.

@aalwash
Copy link
Contributor Author

aalwash commented Jan 9, 2018

Sure, I started working an simple PoC, so you guys can see how it works

@aiolos
Copy link
Contributor

aiolos commented Feb 22, 2018

Hi @aalwash

How's the PoC going? Already something we can have a look at?

@aalwash
Copy link
Contributor Author

aalwash commented Feb 26, 2018

Hi @aiolos

I did make a start a while ago, but some other priorities kept me busy
I will do my best to resume working on this FR this week

@aiolos
Copy link
Contributor

aiolos commented Feb 27, 2018

No worries, I also had a bit of a quiet period on Dashticz. I was just wondering if I had maybe missed something.

aalwash added a commit to aalwash/dashticz_v2 that referenced this issue Apr 15, 2018
…rted the coins block into a template

I couldn't test liteBit, since it doesn't work for me

Issue Dashticz#245
@aalwash
Copy link
Contributor Author

aalwash commented Apr 15, 2018

@aiolos @robgeerts
I did a first commit, so maybe you guys can look into it? I've commited to a separate branch, so you can test it easily: https://github.com/aalwash/dashticz_v2/tree/introduction-ractive

So the ideas is as follow:

  • Ractive will be loaded by default
  • When using any block, you can call var dashticz = new Dashticz(), it's a Singleton, so the next call will re-use the same instannce
  • The new Dashticz "class" (it's a prototype, since I can't use ECMA6 classes) should become the more robust "single-point" of access. The idea would be to move the config to this class as well
  • The Dashticz class will start having modules/plugins, for now I introduced the Dashticz.Template() module

Template module

  • This module handles the fetching & inserting of templates
  • It uses internal variables to cache the results (can be turned off, to refetch) so less of network calls are done
  • This module also cache the Ractive objects, by element id, this way no re-inserting of HTML blocks is needed. ONLY the variables that are changed, will be redrawn (a major performance upgrade!!)

Let me know what you think about this

Note

  • Litebit doesn't work for me, I get errors. So I didn't convert that one yet. Am I the only one that is getting errors?

@aalwash
Copy link
Contributor Author

aalwash commented Apr 16, 2018

In case you want to see the diff, use this url aalwash@5ed60db

@aalwash
Copy link
Contributor Author

aalwash commented Apr 18, 2018

Did anyone check it out :)?

@aalwash aalwash closed this as completed Apr 18, 2018
@aalwash aalwash reopened this Apr 18, 2018
@robgeerts
Copy link
Collaborator

Sorry, busy times for me (as always).
I'll try checking this out tonight!

@aiolos
Copy link
Contributor

aiolos commented Apr 18, 2018

Hi,

I didn't check it out yet. These days a bit busy on other things, but I'll definitely have a look. It sounds promising.

Cheers

@aalwash
Copy link
Contributor Author

aalwash commented Apr 18, 2018

No problem, take your time :)

I already trying to experiment with unit testing and JS code that is normally written for browsers :(

@robgeerts
Copy link
Collaborator

Just tested it, works great :)
1 thing though; I had to manually add the ractive.min.js file, it was missing in the branch...

@aalwash
Copy link
Contributor Author

aalwash commented Apr 19, 2018

@robgeerts hmm, strange, I somehow forgot to add that.

I will try to continue working on a simple unit test for now and I will do a PR after that

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

No branches or pull requests

3 participants