Giter Site home page Giter Site logo

Comments (6)

yasserf avatar yasserf commented on May 2, 2024

Yep, this saves unnecessary messages from being sent to the server / clients.

When would you need it to fire twice?

from deepstream.io.

jwanglof avatar jwanglof commented on May 2, 2024

Our use-case would be if someone writes the same message twice. We have a snippet that our clients have a subscription on and changes as soon as a message is written. If this message is the same this subscription won't fire.

Where is this check done?
Maybe I can do a PR with an extra option that allows a message to be sent without the check

from deepstream.io.

yasserf avatar yasserf commented on May 2, 2024

Would it be possible to use a separate fields on the record that contains the last modified date ( or something that changes ) which will force subscriptions to run?

function update( record, path, value ) {
    record.set('testValue', 1);
    record.set('lastModified', Date.now() )
}

// Client A
var record = deepstream.record.getRecord('user/johan');
update( record, 'testValue', 1 );
update( record, 'testValue', 1 );

// Client B
var record = deepstream.record.getRecord('user/johan');

function updated() {
    console.log('Value changed to: ' + record.getValue('testValue') );
}

record.subscribe('testValue', updated);
record.subscribe('lastModified', updated);

Another alternative would be to use an event saying that the record has changed.

function update( record, path, value ) {
    if( record.get( 'testValue' ) === value ) {
         record.set('testValue', 1);
    } else {
         ds.event.emit( 'user/johan-updated' ); //needs better name!
    }
}

// Client A
var record = deepstream.record.getRecord('user/johan');
update( record, 'testValue', 1 );
update( record, 'testValue', 1 );

// Client B
var record = deepstream.record.getRecord('user/johan');
record.subscribe('testValue', function (newValue) {
    console.log('Value changed to: ' + newValue);
});
ds.event.subscribe(  'user/johan-updated' , function() {
  var value = record.getValue( 'testValue' )
} )

from deepstream.io.

jwanglof avatar jwanglof commented on May 2, 2024

Yes, we have a timestamp-field that contains the last modified snippet-time which I'm using now as a "work-around", but I guess this works just fine as well =)

I was just curious if the original question was true or not. But would it be hard to implement a third argument to record.set()?
Some kind of force-change-event (or something).
I.e.:

var record = deepstream.record.getRecord('user/johan')
record.set('testValue', 1, true);

I realize this would be hard to implement on both PATCH and UPDATE.

from deepstream.io.

yasserf avatar yasserf commented on May 2, 2024

Just spoke with core team and we decided we won't accept any API changes for this since it conflicts with the core idea that a record is just a distributed state. So setting the same value multiple times doesn't actually change that.

But in answer to where it happens:

Sending things out should be easy ( remove a guard ):

https://github.com/hoxton-one/deepstream.io-client-js/blob/master/src/record/record.js#l101

Getting updates from server would be harder, since we currently only emit things that have changed, incase clientA updated the object and clientB only cared about certain paths.

https://github.com/hoxton-one/deepstream.io-client-js/blob/master/src/record/record.js#l460

I would personally recommend using the event approach as you shouldn't need to store any unrequired metadata to determine if something has changed to the same value.

from deepstream.io.

jwanglof avatar jwanglof commented on May 2, 2024

Seems reasonable =)
Thanks for the answers, closing this issue as I think I got my question answered.

from deepstream.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.