edwardsmarkf
edwardsmarkf

Reputation: 1417

deepstream list subscribing to data

is it possible in deepstream to subscribe to data using a list? it appears that changes to the data does not trip the subscribe() function, only something like an addEntry() appears to affect the list subscription.

const   deepstream      = require('deepstream.io-client-js')            ;
const   util            = require('util')                               ;

const   client  = deepstream('localhost:6020').login();

var obj_1       =       { 'sequelizeName':'Mark', 'sequelizeAddr':'123 Elm Lane'    , 'sequelizeId':'1111'};
var obj_2       =       { 'sequelizeName':'Lori', 'sequelizeAddr':'948 Maple Street'    , 'sequelizeId':'2222'};

const rec_1     = client.record.getRecord('obj_one');
const rec_2     = client.record.getRecord('obj_two');

rec_1.set(obj_1);
rec_2.set(obj_2);

var listTest    =       client.record.getList('listTest');

listTest.setEntries(    ['obj_one' ,'obj_two' ] );

listTest.subscribe( (result) => {
        console.log('LIST SUBSCRIBE: ' + util.inspect(result));
})

setTimeout( () =>       {
        obj_1.sequelizeAddr = '321 New Address';
        rec_1.set(obj_1); // how can this change show up in the list subscribe?
}, 2000 );

I have been encouraged to try a new approach using lists, but I am unclear how to subscribe to changes in the data itself using a list, except to somehow have some sort of "generic" or "global" subscribe, which i am not sure is even possible.

Or is there some way I can subscribe using an anonymous record?

Upvotes: 1

Views: 519

Answers (2)

edwardsmarkf
edwardsmarkf

Reputation: 1417

this suggestion was made by both wolfram and phillipp:

class User{
    constructor( recordName ) {
        this.record = ds.record.getRecord( recordName );
        this.record.subscribe( this._processUpdate.bind( this ) );
    }

    _processUpdate( data ) {
        if( this.record.name === '...') {
            // do stuff
        }
    }
}

this works great. thank you both.

Upvotes: 0

Phillipp
Phillipp

Reputation: 1445

Lists are just arrays of strings. Your list content is not connected to the actual record. You can't even assume that a list entry is a record name. You would need to subscribe to each record name in a list manually to get its content updates.

Upvotes: 1

Related Questions