Static Private _mutationObserverConfig
_mutationObserverConfig: object
attributeOldValue
attributeOldValue: boolean = false
attributes
attributes: boolean = false
characterData
characterData: boolean = false
characterDataOldValue
characterDataOldValue: boolean = false
childList
childList: boolean = true
subtree
subtree: boolean = true
The
ControlManageris what makes the view/control engine in Orange tick. It listens to changes in the area of the DOM it is responsible for and reacts toHTMLElementswith the attributesdata-viewanddata-controlbeing added or removed.All views/controls created by the control manager have to be based on the Control class.
Usage
The control manager needs a container and information about which part of the DOM to manage.
let container = new Orange.Modularity.Container(); let controlManager = new Orange.Controls.ControlManager(container); controlManager.manage(document.body);The call to
manage(element: HTMLElement)will perform a one time sweep of the given area of the DOM to create any views/controls present at that given moment. After that the manager will listen to changes and react to them.When a HTMLElement is added
When an element is added the control manager attempts to create the view/control being requested and initialize it correctly.
For example, say we have the view defined by the class:
namespace MyViews { @Orange.Modularity.inject export class MyMainView extends Orange.Controls.KnockoutViewBase { constructor(vm: MyMainViewViewModel) { super('My-Template-Id', vm); } } }and we add the element
<div data-view=MyViews.MyMainView"></div>to the are of the DOM being managed by the control manager. TheControlManagerwill notice this and then proceed as follows:Call
Orange.Controls.GetOrInitializeOrangeElementon<div data-view=MyViews.MyMainView"></div>to create/get anIOrangeElementExtensionconnecting the control/view to its associatedHTMLElement.Create an instance of
MyViews.MyMainViewOrange.Modularity.Containerto resolve any classes needed by the class being instantiated (in the example above an instance ofMyMainViewModelwill be provided by the container due to the@Orange.Modularity.injectdecorator being present on the class)Set the
controlproperty on theIOrangeElementExtensionfrom 1 to the instance created in 2Set the
elementproperty on the control/view inherited fromOrange.Controls.Controlto theHTMLElementcausing the instantiation.onElementSet()method inherited fromOrange.Controls.Controlbeing called.Call
applyTemplate()if the view/control has that method.Find any child views/controls and go through this procedure on them, starting at 1.
Call
onControlCreated()inherited fromOrange.Controls.Control.Set the
isInitializedproperty on theIOrangeElementExtensionfrom 1 totrue.Call any
onInializedListenerspresent on theIOrangeElementExtensionfrom 1.When a HTMLElement is removed
When an element is removed from the managed part of the DOM the control manager will react by calling the
disposemethod (inherited fromOrange.Controls.Control) on all controls/views that was connected to elements removed from the DOM.Any disposables (conforms to interface
{ dispose(): void }) added to the control withaddDisposable(disposable: { dispose(): void })(inherited fromOrange.Controls.Control) will also be disposed.See Container for mor information on injection.