DEV Community

Cover image for Rewriting an old project! Part 2: JavaScript

Rewriting an old project! Part 2: JavaScript

Ken Bellows on April 12, 2019

Note This is Part 2 of a miniseries in which I'm revisiting an old weekend hack of mine from college, which I called jSphere (because I was lazy a...
Collapse
 
misterwhat profile image
Jonas Winzen

Awesome! Thanks for sharing!
Canvas is an interesting and powerful thing and we're using it way less it deserves to be used. Maybe a proper UI library that eliminate the verbosity of working with canvas would make it more attractive.

The expressiveness of Javascript increased orders of magnitude more, than anyone would expect. The rewrite of the Dot constructor makes it immediately visible. It's shorter, easier to understand and less error prone, than the ternary typeof checks of arguments. A single ! there is easily overseen or accidentally introduced and yields somewhat around an hour of debugging fun.

I'm looking forward to your next article. 👍😁

Collapse
 
kenbellows profile image
Ken Bellows

You know, now that I'm thinking more about it, there actually is a group of libraries that attempts to do this, and I think they use the canvas: CreateJS, and specifically EaselJS, their main drawing library. I played around with it several years ago and remember having a pretty good experience with it, but I didn't do anything super advanced with it.

Collapse
 
rhymes profile image
rhymes

Jonas, you mean something like d3.js or chart.js or an actual UI library with components and such?

Collapse
 
misterwhat profile image
Jonas Winzen • Edited

Well both libraries serve the needs for data visualizations.
What I meant, were libraries to build full blown interactive UIs, based on canvas. In the (not so recent) past, there was a boom of super fancy Web Apps Sites using Flash only to render their contents.
Building user interactions within canvas is quite verbose, same for rendering UI elements (accessibility could be shimmed by an underlying html construct to support screen readers and text selection).

From what I've heard there is a React renderer that renders to canvas. I don't know how usable it is in reality - but I think that goes into the direction I was thinking of.

Edit: For drawing UI elements I found React Canvas and for drawing interactive graphic content I found React Cova. Their use cases seem to be orthogonal to each other i.e. you cant replace one with the other).

Thread Thread
 
rhymes profile image
rhymes

What I meant, were libraries to build full blown interactive UIs, based on canvas. In the (not so recent) past, there was a boom of super fancy Web Apps Sites using Flash only to render their contents.

I have only one question: why? Why this would be something that's needed? I'm not sure I understand. Thank you!

Thread Thread
 
kenbellows profile image
Ken Bellows

Games are the first thing that come to my mind. Title screens and menus and such with clickable components. Entire web apps in a Flash style are hopefully gone for good though 😬

Collapse
 
rhymes profile image
rhymes

Nice adventure Ken!

Have you considered using a library for drag & drop and touch handling? It seems like the sort of thing that a library that's already worked out the kinks an compatibility issues would provide for "free".

Collapse
 
kenbellows profile image
Ken Bellows

Oh yeah, there are several libraries out there. If I decide to come back to it I might use one, though I may just use it as an excuse to learn the details of touch gestures, which I expect would be tedious, but worth doing once for the deep knowledge