Skip to content

Commit

Permalink
Port ElementToScopeBinding to Binding API #37 (#54)
Browse files Browse the repository at this point in the history
* Port ElementToScopeBinding to Binding API #37

* use method syntax
  • Loading branch information
TitanNano authored Dec 6, 2021
1 parent f082dc2 commit 9a9b12d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 53 deletions.
52 changes: 0 additions & 52 deletions lib/ElementToScopeBinding.js

This file was deleted.

49 changes: 49 additions & 0 deletions lib/bindings/ElementToScopeBinding.js
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;
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { polyInvoke } from './lib/Util.js';
import ViewPort from './lib/ViewPort.js';
import * as Config from './lib/Config';
import './lib/bindings/IfBinding.js';
import './lib/ElementToScopeBinding.js';
import './lib/bindings/ElementToScopeBinding.js';
import './lib/bindings/HtmlBinding.js';
import './lib/bindings/CloakBinding.js';
import './lib/bindings/AttributeBinding';
Expand Down

0 comments on commit 9a9b12d

Please sign in to comment.