This repository has been archived by the owner on Jan 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Node.prototype.bind
Mark Greenwald edited this page Oct 19, 2022
·
1 revision
Extension method to map data from a model to a
Node
and its descendants via binding decorators
- Syntax: {Node} {Node}.bind({any} model)
- Parameters:
model
: {any} The model to bind from- Returns: {
Node
} The node bind was called from- Example:
<div id="view" bind-style-width="width"> <span bind-textContent="text"></span> </div> <script> let view = document.getElementById('view'); let model = { width: '10px', text: 'Some sample text' }; view.bind(model); </script>
Performs a bind on a
Node
with alternative binding behaviors
- Syntax: {Node} Node.prototype.bind.configure({Object} settings, {Node} node, {any} model)
- Parameters:
settings
: {Object
} Overrides for binding behavior
bindingDelim
: {String
} The delimiter used to separate property names in the attribute name. For example:bind-style-width
will bind to aNode
'swidth
style. The default for this setting is'-'
bindingPrefix
: {String
} The attribute name prefix used to identify bindings. The default for this setting is'bind-'
node
: {Node
} The node to bind tomodel
: {any} The model to bind from- Returns: {
Node
} The node that was passed to the call- Example:
<div id="view" custom-bind-style_width="width"> <span custom-bind-textContent="text"></span> </div> <script> let view = document.getElementById('view'); let model = { width: '10px', text: 'Some sample text' }; Node.prototype.bind.configure({ bindingPrefix: 'custom-bind-', bindingDelim: '_' }, view, model); </script>
Retrieves the settings from a
Node
if it was used in a binding operation. Can write/overwrite new settings causing aNode
to become a new binding scope.
- Syntax: {Object} Node.prototype.bind.settings({Node} node[, {Object} settings])
- Parameters:
node
: {Node
} TheNode
to read from- (optional)
settings
: {Object
} (re)configures/(re)scopes the node causing ancestor bind operations to stop at this node
bindingDelim
: {String
} The delimiter used to separate property names in the attribute name. For example:bind-style-width
will bind to aNode
'swidth
style. The default for this setting is'-'
bindingPrefix
: {String
} The attribute name prefix used to identify bindings. The default for this setting is'bind-'
- Returns: {
Object
} The settings instance, if any, set on thisNode
- Example:
<div id="outer"> <span bind-textContent="text"></span> <!-- Will get binding --> <div id="inner"> <span bind-textContent="text"></span> <!-- Will not get binding --> </div> </div> <script> let outer = document.getElementById('outer'); let inner = document.getElementById('inner'); Node.prototype.bind.settings(inner, {}); // <-- Starts a new, blocking scope at #inner outer.bind({text: 'outer text only'}); // <-- Will not bind past #inner </script>