dwyl / learn-elm-architecture-in-javascript

:unicorn: Learn how to build web apps using the Elm Architecture in "vanilla" JavaScript (step-by-step TDD tutorial)!
https://todomvc-app.herokuapp.com
GNU General Public License v2.0
213 stars 19 forks source link

Multiple Counters on the Same Page 😮 #40

Closed nelsonic closed 6 years ago

nelsonic commented 6 years ago

It occurred to me while applying the Elm Architecture to my little "side project": https://github.com/nelsonic/time-mvp/issues/33 That there's a "gap" in this tutorial, namely: how do we have a more "complex" model (all the examples in the tutorial, currently have model as an int)

I propose that we: write an "exercise for the reader" to: a) refactor the model in the "reset counter" example to use an Object e.g: var model = { counters:[0] } where the value of the first element in the model.counters Array is the value for the single counter example. b) using the var model = { counters:[0] } approach, display multiple counters on the same page. c) write tests for the scenario where there are multiple counters on the same page.

nelsonic commented 6 years ago

As soon as you attempt to change the model everything will "break": image

This is understandable! it's like trying to put a different/new fuel in your old car! it's won't run!

nelsonic commented 6 years ago

Showing multiple counters: image

nelsonic commented 6 years ago

multiple instances: elm-arch-multiple-counters-naive

nelsonic commented 6 years ago

Multiple counters using the same App: image