These are chat archives for orbitjs/orbit.js

2nd
Feb 2016
Oliver Searle-Barnes
@opsb
Feb 02 2016 19:27
@dgeb another little fix orbitjs/orbit.js#251
Dan Gebhardt
@dgeb
Feb 02 2016 19:34
@opsb can you explain .filter(operation => operation) ?
Oliver Searle-Barnes
@opsb
Feb 02 2016 19:35
yeah, it’s basically [1, null].compact but for streams
filter will allow values through when it’s callback evaluates to true
(maybe that’s a better way to put it :) )
Dan Gebhardt
@dgeb
Feb 02 2016 19:36
right, I got that about filter()
Oliver Searle-Barnes
@opsb
Feb 02 2016 19:36
ah, you mean why’s it necessary? right
Dan Gebhardt
@dgeb
Feb 02 2016 19:36
so there are cases when it's obviously not true?
yeah
Oliver Searle-Barnes
@opsb
Feb 02 2016 19:38
yeah, the live query operators currently pass through all Operations
qb.recordsOfType(‘planet’)
  .filter(qb.get(’name’).eq(‘Pluto’))
ok, so if a planet’s name is updated the filter needs to reevaluate
it knows to do this because recordsOfType passed through the updateAttribute operation
we don’t want to emit these updates from cache.liveQuery() though so at that point they’re filtered out
  liveQuery(exp) {
    return this
      .liveQueryEvaluator.evaluate(exp)
      .map(operation => {
        switch (operationType(operation)) {
          case 'addRecord': {
            return addRecordToSetOperation(operation.value);
          }
          case 'removeRecord': {
            const identifier = { type: operation.path[0], id: operation.path[1] };
            return removeRecordFromSetOperation(identifier);
          }
        }
      })
      .filter(operation => operation);
  },
Oliver Searle-Barnes
@opsb
Feb 02 2016 19:43
so here the operation could be anything, but we only want to emit addRecordToSet or removeRecordFromSet which correspond to addRecord and removeRecord
because it’s a map it will always return something, so any updates will cause undefined to be emitted
Dan Gebhardt
@dgeb
Feb 02 2016 19:43
ahhhh .... I wasn't focusing on the map
ty :)
makes total sense now ... thanks for the thorough explanation
Oliver Searle-Barnes
@opsb
Feb 02 2016 19:44
great
Dan Gebhardt
@dgeb
Feb 02 2016 19:45
merged :shipit:
Oliver Searle-Barnes
@opsb
Feb 02 2016 19:45
I am hoping to change the live query operators to only use addRecordToSet / removeRecordFromSet and the TBD recordUpdate
thanks!
I’ve recycled the existing operations but they’re not a great fit for the liveQuery operators
anyway, works for now
Dan Gebhardt
@dgeb
Feb 02 2016 19:45
yeah, that will be better, agreed