Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite loop in has binder #44

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ expect(foo.a.b).toBe(50); // new one updated
expect(a.b).toBe(30); // from before it was orphaned
```

### Strings

String concatenation is straightforward.

```javascript
var object = {name: "world"};
bind(object, "greeting", {"<-": "'hello ' + name + '!'"});
expect(object.greeting).toBe("hello world!");
```

### Sum

Some advanced queries are possible with one-way bindings from
Expand Down Expand Up @@ -858,7 +868,7 @@ expect(object.hasNeedle).toBe(true);

`has` bindings are not incremental, but with the right data-structure,
updates are cheap. The [Collections][] package contains Lists, Sets,
and OrderedSets that all can send content change notifications and thus
and OrderedSets that all can send ranged content change notifications and thus
can be bound.

```javascript
Expand All @@ -868,6 +878,19 @@ object.haystack = new Set([1, 2, 3]);
expect(object.hasNeedle).toBe(true);
```

Likewise, Maps implement `addMapChangeListener`, so you can use a `has` binding
to observe whether an entry exists with the given key.

```javascript
// Continued from above...
var Map = require("collections/map");
object.haystack = new Map([[1, "a"], [2, "b"]]);
object.needle = 2;
expect(object.hasNeedle).toBe(true);
object.needle = 3;
expect(object.hasNeedle).toBe(false);
```

`has` bindings can also be left-to-right and bi-directional.

```javascript
Expand Down
161 changes: 92 additions & 69 deletions binders.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions observe.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ function observe(source, expression, descriptorOrFunction) {
return descriptor.change.apply(source, arguments);
} else if (typeof contentChange === "function") {
value.addRangeChangeListener(contentChange);
return Observers.once(function () {
return function () {
value.removeRangeChangeListener(contentChange);
});
};
}
}), sourceScope);
}
Expand Down
Loading