I have a parent object VM. It holds a child object that also have observable properties.
The child object has the following properties
- private observable array that serves as the datasource for a select HTML element on the UI.
- public computed that controls read write access to the private observable array.
- private observable selectedValue property that serves as the datasource for the value attribute of the select HTML element.
- public computed selectedValue property that controls access to the private observable selectedValue.
Flow:
- xhr gets list from server
- download function creates an array and sets the private observable array to the new array via its public computed property's write function.
- This same write function also sets the selectedValue private observable property via its public computed property.
Ultimately, what I get is a populated select HTML element and a value set as a default selection. By using the public computed interface to the private observables, I get an input validation hook.
This all works great. However, i have a need to provide an update to the parent VM whenever the selected value changes. I am a newbie to KO and, at first, I did not know about the subscribe method. Therefore, I implemented my own observer pattern that called back to the parent VM from within the write function of the public computed selectedValue property. This worked great.
Later I learned about the subscribe function offered by KO. So I disabled my observer pattern and subscribed the parent VM to the selectedValue public computed property on the child VM object. When I test the design, I get an error from KO. Uncaught TypeError: Property 'ha' of object [object Object] is not a function. I tracked this and this occurs when the write function of the public computed selectedValue property attempts to update the private observable selectedValue property it protects.
Any throughs?
There is no ha property anywhere in my code so this must be something set by KO internally.