Created Friday 28 February 2014
Recall Views subscribe to models and when a model changes it publishes changes to its observers.
Use hidden INPUT fields as models?
- Pros: built-in framework to subscribe/publish events
- Cons: probably bad practice since it leads to complex code
- Theoretically, INPUT fields are supposed to fire
onchangewhenever the INPUT changes... even when you change the value inside the observer attached to theonchangeevent. You need to check for who fired theonchangeto prevent infinite loops (the observer noticing a change in the INPUT field so it changes the INPUT field which triggers the observer ... ) - If you use INPUT fields as a model you need to manually fire an
onchangeevent when you update the data because this doesn't automatically happen.
To summarize, every observer must do the following:
- figure out who is calling it (to prevent infinite loops)
- keep track of whether or not a change occurs