derbyjs / derby

MVC framework making it easy to write realtime, collaborative applications that run in both Node.js and browsers
http://derbyjs.com
4.73k stars 264 forks source link

Calling .get() on a keyed reference to another reference collection returns getter function #179

Closed absoludity closed 10 years ago

absoludity commented 11 years ago

I recently updated the todomvc project to use a more recent derby due to

https://github.com/addyosmani/todomvc/issues/338 which was a result of https://github.com/codeparty/derby/issues/171

It solved the "DERBY is not defined" error, but seems to have found another:

model.set('colors', {
  red: {hex: '#f00', id: 'red'}
, green: {hex: '#0f0', id: 'green'}
, blue: {hex: '#00f', id: 'blue'}
});
model.ref('_colors.favourite', model.filter('colors').where('id').equals('red'))
model.ref('_colors.notfavourite', model.filter('colors').where('id').equals('green'))
model.set('_filter', 'favourite')
model.ref('_keyedRef', '_colors', '_filter')
model.get('_keyedRef')

Expected output:

[{hex: '#f00', id: 'red'}]

Actual output:

function getter(data, pathToRef, rest, refEmitter, prevRests) {
    if (! prevRests) {
      prevRests = [rest];
    } else {
      prevRests.push(rest);
    }
    var out = treeLookup(data, to, {prevRests: prevRests});
    prevRests.pop();
    refEmitter && refEmitter.emit('refWithoutKey', out.node, out.path, rest, hardLink);
    if (typeof out.node === 'undefined') out.halt = true;
    return out;
  }

I've worked around it for the moment by always setting an unkey-ed ref: https://github.com/addyosmani/todomvc/pull/340/files

nateps commented 10 years ago

Master of Derby is now the rewritten 0.6 and I am removing previous issues pretty aggressively so that I can be more responsive to new issues.

Please re-open if this issue is still relevant in Derby 0.6.