BindChain (ui)
@ckeditor/ckeditor5-ui/src/template
The return value of Template.bind()
. It provides to()
and if()
methods to create the observable attribute and event bindings.
Filtering
Type parameters
-
TObservable
Methods
-
if( attribute, [ valueIfTrue ], [ callback ] ) → AttributeBinding
module:ui/template~BindChain#if
Binds an observable to an HTML element attribute or a text node
textContent
so it remains in sync with the observable attribute as it changes.Unlike
to
, it controls the presence of the attribute ortextContent
depending on the "falseness" of anObservable
attribute.const bind = Template.bind( observable, emitter ); new Template( { tag: 'input', attributes: { // <input checked> when `observable#a` is not undefined/null/false/'' // <input> when `observable#a` is undefined/null/false checked: bind.if( 'a' ) }, children: [ { // <input>"b-is-not-set"</input> when `observable#b` is undefined/null/false/'' // <input></input> when `observable#b` is not "falsy" text: bind.if( 'b', 'b-is-not-set', ( value, node ) => !value ) } ] } ).render();
Learn more about using
if()
in theTemplateValueSchema
.Type parameters
TAttribute : extends string
Parameters
attribute : TAttribute
An attribute name of
Observable
used in the binding.[ valueIfTrue ] : unknown
Value set when the
Observable
attribute is not undefined/null/false/'' (empty string).[ callback ] : ( TObservable[ TAttribute ], Node ) => ( true | FalsyValue )
Allows for processing of the value. Accepts
Node
andvalue
as arguments.
Returns
-
to( attribute, callback ) → AttributeBinding
module:ui/template~BindChain#to:ATTRIBUTE_CALLBACK
Binds an observable to either:
- an HTML element attribute or a text node
textContent
, so it remains in sync with the observable attribute as it changes, - or an HTML element DOM event, so the DOM events are propagated through an observable.
Some common use cases of
to()
bindings are presented below:const bind = Template.bind( observable, emitter ); new Template( { tag: 'p', attributes: { // class="..." attribute gets bound to `observable#a` class: bind.to( 'a' ) }, children: [ // <p>...</p> gets bound to observable#b; always `toUpperCase()`. { text: bind.to( 'b', ( value, node ) => value.toUpperCase() ) } ], on: { click: [ // An observable will fire "clicked" upon "click" in the DOM. bind.to( 'clicked' ), // A custom callback will be executed upon "click" in the DOM. bind.to( () => { ... } ) ] } } ).render();
Learn more about using
to()
in theTemplateValueSchema
andTemplateListenerSchema
.Type parameters
TAttribute : extends string
Parameters
attribute : TAttribute
An attribute name of
Observable
.callback : ( TObservable[ TAttribute ], Node ) => TemplateSimpleValue
Allows for processing of the value. Accepts
Node
andvalue
as arguments.
Returns
- an HTML element attribute or a text node
-
to( eventNameOrCallback ) → ListenerBinding
module:ui/template~BindChain#to:EVENT
Binds an observable to either:
- an HTML element attribute or a text node
textContent
, so it remains in sync with the observable attribute as it changes, - or an HTML element DOM event, so the DOM events are propagated through an observable.
Some common use cases of
to()
bindings are presented below:const bind = Template.bind( observable, emitter ); new Template( { tag: 'p', attributes: { // class="..." attribute gets bound to `observable#a` class: bind.to( 'a' ) }, children: [ // <p>...</p> gets bound to observable#b; always `toUpperCase()`. { text: bind.to( 'b', ( value, node ) => value.toUpperCase() ) } ], on: { click: [ // An observable will fire "clicked" upon "click" in the DOM. bind.to( 'clicked' ), // A custom callback will be executed upon "click" in the DOM. bind.to( () => { ... } ) ] } } ).render();
Learn more about using
to()
in theTemplateValueSchema
andTemplateListenerSchema
.Parameters
eventNameOrCallback : string | ( Event ) => void
A DOM event name or an event callback.
Returns
- an HTML element attribute or a text node
-
to( attribute ) → object
module:ui/template~BindChain#to:ATTRIBUTE
Binds an observable to either:
- an HTML element attribute or a text node
textContent
, so it remains in sync with the observable attribute as it changes, - or an HTML element DOM event, so the DOM events are propagated through an observable.
Some common use cases of
to()
bindings are presented below:const bind = Template.bind( observable, emitter ); new Template( { tag: 'p', attributes: { // class="..." attribute gets bound to `observable#a` class: bind.to( 'a' ) }, children: [ // <p>...</p> gets bound to observable#b; always `toUpperCase()`. { text: bind.to( 'b', ( value, node ) => value.toUpperCase() ) } ], on: { click: [ // An observable will fire "clicked" upon "click" in the DOM. bind.to( 'clicked' ), // A custom callback will be executed upon "click" in the DOM. bind.to( () => { ... } ) ] } } ).render();
Learn more about using
to()
in theTemplateValueSchema
andTemplateListenerSchema
.Type parameters
TAttribute : extends string
Parameters
attribute : TAttribute
An attribute name of
Observable
.
Returns
object
- an HTML element attribute or a text node
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features. We appreciate your feedback to help us ensure its accuracy and completeness.