From 6eb09c1a796f636ce45c9589a47a40f37e4ed2ac Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 25 Aug 2016 12:17:09 -0700 Subject: Add persistent form class --- docs/form_persisting_architecture.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/form_persisting_architecture.md b/docs/form_persisting_architecture.md index 8b5ab495f..9e6cb7c41 100644 --- a/docs/form_persisting_architecture.md +++ b/docs/form_persisting_architecture.md @@ -10,5 +10,26 @@ Since: Whenever this class is loaded, it registers an `onChange` listener. On those events, it checks the target for a special ID attribute it listens for. -Let's say we call our class `PersistentForm`. So then we might check for a `persistent-form-id`. +Let's say we call our class `PersistentForm`. So then we might check for a `persistent-form-id` on change. + +The parent element will define a special attribute, let's say `persistent-form-parent-id`. + +Here's some pseudo-code for it: +``` +onChange(ev) => + persisted = localStorage[parentKey] + persisted[childKey] = ev.value + localStorage[parentKey] = persisted +``` + +On startup, we just do the inverse: + +``` +onStart() => + el = this.getEl() + parentKey = el.attr('persistent-form-parent-id') + children = el.children.where('[persistent-form-id]') + children.each(loadValue) +``` + -- cgit v1.2.3