Comments (1)
Thanks for the feedback, much appreciated!
I'll divide your questions into a few parts, they are also ordered a bit different to in your question.
I don't understand why a message reading the record is setting its data, or am I misinterpreting something?
When a record is requested from deepstream it tries to load its current state, and if the record doesn't exist will create it as an empty object and return that value.
Once that value is retrieved it will then fire the whenReady event, which means the record has set its data to be in sync with what the server has and you can start using it.
Since requesting the record the first time is an async operation, this._$data will be updated with the current state of the record from the server as soon as it is loaded, which is why it is being overriden on read events.
Produces an empty object rather than an empty array
The way lists work is they provide convenience APIs ontop of a normal record. This is to make it easier than having to deal with arrays directly and provide extra callbacks.
What you raised is actually a bug in the API where it exposes the default record content when it's first created ( which is an empty object ).
The method getEntries could instead be used to return an array instead so your code would look like this:
var shrubs =ds.record.getList('shrubs');
*wait a bit, or wrap in .whenReady()*
shrubs.subscribe(function(shrubEntries) { console.log('shrubEntries', shrubs.getEntries() ) }, true);
Doesn't log anything unless the subscribe is separated and wrapped in a .whenReady()
This is intended behaviour, since no events are actually fired until the isReady event occurs.
In your example:
ds.record.getList('shrubs').subscribe(function(shrubEntries) { console.log('shrubEntries', shrubEntries) }, true);
Since shrubEntries is not yet loaded from the server, you can't actually be told what the current state is.
By putting it in whenReady:
ds.record.getList('shrubs').whenReady( function() {
subscribe(function(shrubEntries) { console.log('shrubEntries', shrubEntries) }, true);
} );
It's now saying that as soon as the information is loaded from the server ( its initial state ) subscribe to the any changes and be told what the initial value is.
In your case of finding out if it's loaded or not would be:
// Set Default Loading Behaviour
var list = ds.record.getList('shrubs');
list.whenReady( function() {
subscribe( function( shrubEntries ) {
var shrubEntries = list.getEntries();
}, true);
// Remove loading behaviour ( this should only be triggered once during the list lifetime )
} );
Normally, using records, you won't need to use closures, but given the issue mentioned in part 2 the record is still exposed in a few callbacks instead of the list. Raised #33 as well to capture that.
Hope this helps, and feel free to let me know if something doesn't make sense!
from deepstream.io-client-js.
Related Issues (20)
- Client hangs on write when no permissions available HOT 5
- dist directory/.js-file for browser is missing HOT 12
- Deepstream-client have not worked in ReactNative HOT 3
- C and Options are not exported from dist/bundle/ds.min.js HOT 1
- Problem of usage in nodejs 14.5 with the lastest version of @deepstream/[email protected] HOT 10
- Can't subscribe to a record with record.subscribe(callback) with callback being the only param because of Typescript definitions. HOT 7
- client.presence.subscribe('username', callback) not working HOT 1
- ACCEPT_TIMEOUT weired behavior HOT 4
- getting error referrence error HOT 1
- Issue an event to a user by their ID HOT 1
- In chrome, new DeepstreamClient, then the XmlHttpRequest won't work. HOT 1
- How can I make data timeout auto clear? HOT 1
- DeepstreamClient - RPC ResponseTimeout HOT 1
- Uncaught ReferenceError: Buffer is not defined HOT 6
- NextJS 13 - PNPM - bufferuntil HOT 2
- Deprecate old SDK HOT 2
- Doesn't works with React Native (Expo) With Hermes HOT 7
- Discard list still get event handler triggered HOT 1
- Record subscription after reconnect HOT 9
- Cannot use deepstream-client-js in React Native app android HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deepstream.io-client-js.