-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Port ElementToScopeBinding to Binding API #37 * use method syntax
- Loading branch information
Showing
3 changed files
with
50 additions
and
53 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import BindingApi from '../BindingApi.js'; | ||
|
||
const ElementToScopeBinding = { | ||
|
||
/** | ||
* @type {string} | ||
*/ | ||
name: 'scope-id', | ||
|
||
/** | ||
* @type {Node} | ||
*/ | ||
parentNode: null, | ||
|
||
/** | ||
* @constructs | ||
* @extends {module:DataBinding.Binding} | ||
* | ||
* @param {Node} parentNode parent node of this binding | ||
* @param {Object} scopeInfo scope metadata object | ||
* @param {string} text original text value of the binding | ||
* | ||
* @return {void} | ||
*/ | ||
_make({ node, text }) { | ||
super._make.apply(this); | ||
|
||
this.parentNode = node; | ||
this.text = text; | ||
|
||
BindingApi(this).attachBinding(this); | ||
}, | ||
|
||
update(scope) { | ||
/** @type {Node} */ | ||
let currentValue = BindingApi(this).parser.parseExpression(this.text, scope); | ||
|
||
if (currentValue !== this.parentNode) { | ||
BindingApi(this).parser.assignExpression(this.text, scope, this.parentNode); | ||
scope.update(); | ||
} | ||
}, | ||
|
||
__proto__: BindingApi().Binding, | ||
}; | ||
|
||
BindingApi().registerBinding(ElementToScopeBinding); | ||
|
||
export default ElementToScopeBinding; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters