Skip to content

Commit

Permalink
Refactor element matching.
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinRixham committed Apr 4, 2017
1 parent 6f9e862 commit b67f8db
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 37 deletions.
1 change: 0 additions & 1 deletion src/array/ArrayBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ define([
function ArrayBinding(model, propertyType) {

var properties = [];

var elements = [];

(function createProperties() {
Expand Down
1 change: 0 additions & 1 deletion src/array/ArrayElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ define(["array/ArrayItemElement"], function(ArrayItemElement) {
function ArrayElement(domElement, initialLength) {

var element = domElement.get();

var child;

(function checkElementHasOnlyOneChild() {
Expand Down
1 change: 0 additions & 1 deletion src/array/method/Pop_.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ define([], function() {
model.pop = function() {

var popped = originalPop.apply(this, arguments);

var property = properties.pop();

if (property) {
Expand Down
1 change: 0 additions & 1 deletion src/array/method/Shift.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ define([], function() {
model.shift = function() {

var shifted = originalShift.apply(this, arguments);

var property = properties.shift();

if (property) {
Expand Down
7 changes: 3 additions & 4 deletions src/callback/CallbackBinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ define([

var elements = getMatchingElements(scope, name);

bindElements(elements, scope, model);
bindElements(elements, model);
addElements(elements);
};

Expand Down Expand Up @@ -62,14 +62,13 @@ define([
}
}

function bindElements(elements, scope, model) {
function bindElements(elements, model) {

for (var i = 0; i < elements.length; i++) {

var element = elements[i];

if (scope.hasInScope(element) &&
!boundElements.contains(element)) {
if (!boundElements.contains(element)) {

binding.setUpElement(model, element.get());
new Registry().requestRegistrations();
Expand Down
14 changes: 12 additions & 2 deletions src/element/DOMElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,19 @@ define([
if (isNaN(key)) {

var elements = element.querySelectorAll("[data-bind=" + key + "]");
var elementsArray = [].slice.call(elements);
var elementsArray = [];

return elementsArray.map(function(item) { return new DOMElement(item); });
for (var i = 0; i < elements.length; i++) {

var newElement = new DOMElement(elements[i]);

if (this.hasInScope(newElement)) {

elementsArray.push(newElement);
}
}

return elementsArray;
}
else {

Expand Down
2 changes: 1 addition & 1 deletion src/element/NullDOMElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ define([], function() {

this.getMatchingElements = function() {

return [new NullDOMElement()];
return [];
};

this.hasDataBindAttribute = function() {
Expand Down
19 changes: 8 additions & 11 deletions src/object/ObjectBinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,16 @@ define([

var element = elements[i];

if (scope.hasInScope(element)) {
if (boundElements.contains(element)) {

if (boundElements.contains(element)) {

binding.updateElement(model, element, model && model[name]);
}
else {
binding.updateElement(model, element, model && model[name]);
}
else {

binding.setUpElement(model, element, model && model[name]);
new Registry().requestRegistrations();
binding.updateElement(model, element, model && model[name]);
binding.createCallback(scope, element);
}
binding.setUpElement(model, element, model && model[name]);
new Registry().requestRegistrations();
binding.updateElement(model, element, model && model[name]);
binding.createCallback(scope, element);
}
}
}
Expand Down
23 changes: 9 additions & 14 deletions src/object/ViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ define([
function ViewModel(model) {

var boundElements = new ElementSet();

var transientProperties = {};

var permanentProperties = {};

new Serialisable(model);
Expand Down Expand Up @@ -46,20 +44,17 @@ define([

function bindElement(element, scope, name) {

if (scope.hasInScope(element)) {

if (!boundElements.contains(element)) {
if (!boundElements.contains(element)) {

createRebinder(element, scope, name);
element.callBindingCallback(model);
}

unbindOldProperties();
createPermanentProperties();
createTransientProperties();
bindProperties(element);
boundElements.add(element);
createRebinder(element, scope, name);
element.callBindingCallback(model);
}

unbindOldProperties();
createPermanentProperties();
createTransientProperties();
bindProperties(element);
boundElements.add(element);
}

function createRebinder(element, scope, name) {
Expand Down
1 change: 0 additions & 1 deletion src/property/PermanentProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ define([], function() {
function PermanentProperty(property, propertyType) {

var objectBinding;

var propertyInjected = false;

if (typeof(property) == "object" && !isBinding(property)) {
Expand Down

0 comments on commit b67f8db

Please sign in to comment.