diff --git a/lib/ElementToScopeBinding.js b/lib/ElementToScopeBinding.js deleted file mode 100644 index 8508368..0000000 --- a/lib/ElementToScopeBinding.js +++ /dev/null @@ -1,52 +0,0 @@ -import { Make } from '../af/util/make'; -import { assignExpression, parseExpression } from './Parser'; -import Binding from './Binding'; -import BindingRegistry from './BindingRegistry.js'; - -let ElementToScopeBinding = Make(/** @lends module:DataBinding.ElementToScopeBinding.prototype */{ - - /** - * @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: function({ parentNode, scopeInfo, text }) { - Binding._make.apply(this); - - this.parentNode = parentNode; - this.text = text; - - scopeInfo.bindings.push(this); - - }, - - update: function(scope) { - /** @type {Node} */ - let currentValue = parseExpression(this.text, scope); - - if (currentValue !== this.parentNode) { - assignExpression(this.text, scope, this.parentNode); - scope.__apply__(null, true); - } - }, - -}, Binding).get(); - -BindingRegistry.register(ElementToScopeBinding); - -export default ElementToScopeBinding; diff --git a/lib/bindings/ElementToScopeBinding.js b/lib/bindings/ElementToScopeBinding.js new file mode 100644 index 0000000..36e3ff8 --- /dev/null +++ b/lib/bindings/ElementToScopeBinding.js @@ -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; diff --git a/main.js b/main.js index 139e221..8cf6cf5 100644 --- a/main.js +++ b/main.js @@ -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';