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
ControlManager
is 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 toHTMLElements
with the attributesdata-view
anddata-control
being 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. TheControlManager
will notice this and then proceed as follows:Call
Orange.Controls.GetOrInitializeOrangeElement
on<div data-view=MyViews.MyMainView"></div>
to create/get anIOrangeElementExtension
connecting the control/view to its associatedHTMLElement
.Create an instance of
MyViews.MyMainView
Orange.Modularity.Container
to resolve any classes needed by the class being instantiated (in the example above an instance ofMyMainViewModel
will be provided by the container due to the@Orange.Modularity.inject
decorator being present on the class)Set the
control
property on theIOrangeElementExtension
from 1 to the instance created in 2Set the
element
property on the control/view inherited fromOrange.Controls.Control
to theHTMLElement
causing the instantiation.onElementSet()
method inherited fromOrange.Controls.Control
being 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
isInitialized
property on theIOrangeElementExtension
from 1 totrue
.Call any
onInializedListeners
present on theIOrangeElementExtension
from 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
dispose
method (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.