-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support plain JS and ko-es5 models #55
Support plain JS and ko-es5 models #55
Commits on Jun 20, 2018
-
POJO-Support: Compel knockout to generate _ko_property_writers for a …
…few more of its bindings, by marking them as two-way. Some of knockout's built-in bindings (checked, hasFocus, selectedOptions, textInput, and value) are already listed as "two-way bindings" by default. For these, knockout generates an additional binding named "_ko_property_writers" which exposes functions for writing these values to non-observable model properties. We need to tell knockout to generate property writers for more of its built-in bindings, so that `init` can use these to write to the model.
Configuration menu - View commit details
-
Copy full SHA for 920979c - Browse repository at this point
Copy the full SHA 920979cView commit details -
POJO-Support: Added utility method for creating a binding preprocesso…
…r that generates custom property writers. Knockout's _twoWayBindings collection only covers basic `name: value` bindings. For more complex bindings that receive an object literal (including KO's own "attr"), we need to generate property writers ourselves.
Configuration menu - View commit details
-
Copy full SHA for 6d9e532 - Browse repository at this point
Copy the full SHA 6d9e532View commit details -
POJO-Support: Modified
init
binding, to use property writers for no……n-observable model properties. This commit expands on the existing logic of finding and invoking fieldAccessors. But if no fieldAccessor is found, or it is not observable, then look for a suitable property writer instead.
Configuration menu - View commit details
-
Copy full SHA for e09e8db - Browse repository at this point
Copy the full SHA e09e8dbView commit details -
POJO-Support: Modified
foreachInit
binding, so it can work with pla……in arrays, and also subscribe to changes in a knockout-es5 tracked array property. The trickiest part of this commit is setting up the subscription with change tracking. When the array comes from a knockout-es5 "tracked" model, it is actually being read from an ES5 property getter which reads from an internal observableArray. But we don't have access to that underlying observableArray here, so we can't call `array.subscribe(..., "arrayChange")`. Instead, we take advantage of Knockout's dependency tracking and set up a `ko.computed` which reads the array from `valueAccessor()`. This sets up a dependency such that the body of our `computed` will be invoked any time the array changes. This works regardless of whether the model uses an actual observableArray or a ko-es5 tracked array property. Since we can no longer reliably subscribe to the "arrayChange" notification to get the diffs, we need to take on a bit of that responsibility ourselves (basically doing the same as what KO would do if we did subscribe). We keep track of the previous array contents, and then use `ko.utils.compareArrays` to get the differences. (I had to move the biniding's `init` logic into the `InitializedForEach` constructor so that the `ko.computed` could use the `valueAccessor()`)
Configuration menu - View commit details
-
Copy full SHA for e12f6bb - Browse repository at this point
Copy the full SHA e12f6bbView commit details
Commits on Jun 22, 2018
-
* Added knockout-es5 package - This is only required for test and some examples, but is entirely optional when using knockout-pre-render. * Added tests against plain JS models. * Added tests against knockout-es5 tracked models
Configuration menu - View commit details
-
Copy full SHA for 933d546 - Browse repository at this point
Copy the full SHA 933d546View commit details -
* Example that populates a plain JS model. * Example that populates a knockout-es5 model
Configuration menu - View commit details
-
Copy full SHA for 0146a3b - Browse repository at this point
Copy the full SHA 0146a3bView commit details -
POJO-Support: Made array subscription style conditional.
* If the incoming data is observable, subscribe to its changes the normal (simpler) way. * If it's *not* observable, then use the "computed" approach with explicit change tracking. This avoids redundant change tracking in the case the observableArray has multiple subscribers to the 'arrayChange' notification.
Configuration menu - View commit details
-
Copy full SHA for df32fc1 - Browse repository at this point
Copy the full SHA df32fc1View commit details -
Configuration menu - View commit details
-
Copy full SHA for cd61907 - Browse repository at this point
Copy the full SHA cd61907View commit details -
POJO-Support: Styling and comment fixes.
* Removed unnecessary parens around some boolean expressions. * Fixed an error in a comment.
Configuration menu - View commit details
-
Copy full SHA for 1ef7134 - Browse repository at this point
Copy the full SHA 1ef7134View commit details