Closed geohuz closed 1 year ago
you mean that you change a record data but don't want to susbcribe to it? if so, you should use client.record.setData
, look the docs here
Well, not exactly, say if I subscribed to a data and also changed it, I will still get call back from my changes, what I want is exlcude any change initiated from self site but still receive any message from other sides. I'm thinking this behavior will cause dead loop in data operation.
Ok, no you can't do that currently at the server level. Data changes are broadcasted without informing which user made the change. My advice is to review your client side logic in order to avoid loops.
All right, currently I'm using the client.record.has(recordName)
as a way to check the client memory if the record has been fetched, something like:
let localRecordContent = {}
let localRecordExist = await client.record.has(recordName)
if (localRecordExist) {
localRecordContent = client.record.getRecord(recordName).get()
}
not sure if this works.
You're mixing concepts:
client.record.has
tells you wether the record exists in the server (including database/cache if you're using)
If you want to keep track of records at the client level, one way is to use a singleton pattern:
const client = new DeepstreamClient()
const currentRecords = new Map()
const getRecord = (recordName) => {
let record = currentRecords.get(recordName)
if (!record) {
record = client.record.getRecord(recordName)
currentRecords.set(recordName, record)
}
return record
}
const discardRecord = (recordName) => {
const record = getRecord(recordName)
record.discard()
currentRecords.delete(recordName)
}
const deleteRecord = (recordName) => {
const record = getRecord(recordName)
record.delete()
currentRecords.delete(recordName)
}
Thank you @jaime-ez ! That should solve the problem!
Is there a server setting which make sure a provider client doesn't get the change to record/list by itself?