commit 6cefc020d168969ec1bf8beb9aa0ec27e4252bb9
parent c2e955b6a1f11218a578b1e2bf7dc52a4054d936
Author: ebutler <e.c.butler@outlook.com>
Date: Thu, 24 Oct 2019 08:32:25 -0400
Update to KO binding to return reference to editor
Diffstat:
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/src/ko-striveneditor.js b/src/ko-striveneditor.js
@@ -4,17 +4,23 @@ export default class KoStrivenEditor {
constructor(ko) {
ko.bindingHandlers.striveneditor = {
init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
+ // Get options
+ let options = valueAccessor();
+ // Options must be passed as an observable
+ if (!ko.isObservable(options)) {
+ throw "Options must be an observable.";
+ }
- // Unwrap options
- var options = ko.utils.unwrapObservable(valueAccessor());
// Get the value binding in case we are binding the editor's contents to an observable
- var value = allBindings().value;
- if (ko.isObservable(value)) {
- // Pass the value to the editor in options
- options.value = value();
+ let value = allBindings().value;
+ if (value && !ko.isObservable(value)) {
+ throw "Value must be an observable.";
}
-
- let editor = new StrivenEditor(element, options);
+
+ // Pass the value to the editor in options
+ options().value = value();
+
+ let editor = new StrivenEditor(element, options());
let pauseUpdate = false;
// Handle updates and changes to value observable
@@ -35,6 +41,8 @@ export default class KoStrivenEditor {
});
}
+ // Set the editor in options
+ options().api = editor;
}
};