pemrouz/ripple — pull request #3 by pemrouz (2014-10-05 20:53:54+00:00)
Title: Proxies

See [client tests](https://github.com/pemrouz/ripple/blob/proxies/test/client.js#L35-L42) for an example.

The following resource only sends the sum of it's terms to the client, and increases the cardinality on update via changes to the `length` property. Changes to other properties are propagated, but ignored.

Ideally this should be replaced with native ES6 Proxies, if it doesn't complicate the API for users.

I removed the permissions hash for now, because I think we can use just this single hook for that instead.

```js
ripple.resource('proxy.data' , [{i:0}, {i:1},{i:2}], { to: to, from: from })

function from(key, val, body) {
if (key != 'length') return;
for (var i = 0; i < +val; i++) body[i] = { i: i }
}

function to(d) {
return { sum: d.reduce(sum, 0), length: d.length }
}
```