Closed joshuagruenstein closed 8 years ago
It would be cool if fields inside of snooze templates could automagically be represented inside of the snooze object. This would make stuff like reading forms super nice and simple.
On the other hand, it would prohibit reading values from outsize of snooze templates...
OOH I think I've got it. What if we do one way data binding throughout from the DOM to snooze. Similar concept to the way snooze handles handlers. Basically, you specify data-model="whatever"
in the element you want to be able to read from. Automagically, the value of snooze.model['whatever']
would be equal to the value of that element. It would be even fancier if we could do stuff like data-model="thisForm.pass"
, specifying subfields. This establishes two separate flows for data in snooze: pipes for Data --> DOM, and models for DOM --> Data.
Note: deep state binding does not support arrays. This is for a couple of reasons. First, you'd kinda have to instantiate the array beforehand. Second, it's weird to have the possibility of empty spots: making something at index zero and index 6 would require the generation of emptiness between them. Third, it makes bracket syntax kinda arbitrary as to whether it's looking up a key or an element. Brackets are bad, and should not be used inside of data-model
. Finally, arrays in JS are just objects anyway, so this works out nicely.
You can still use snooze models like arrays. For example, if you have a couple inputs labeled data-model="inputs.0"
, data-model="inputs.1"
, data-model="inputs.2"
, and data-model="inputs.3"
, you can still use stuff like snooze.models.inputs[0]
to read data.
Everything works (including dropdowns, unexpectedly). Time to close.
By deep state binding, I mean the ability to do fancy stuff like
data-model="thisForm.pass"
, going however deep or complex as required. This would be uber-fancy when filling arrays with fields autogenerated by templating. All of this should work with the following input elements: