@instantdb/core
Advanced tools
Comparing version 0.8.2 to 0.8.3
@@ -122,2 +122,7 @@ export default class Reactor { | ||
___notifyPresenceSubs(roomId: any): void; | ||
___broadcast({ room, topic, data }: { | ||
room: any; | ||
topic: any; | ||
data: any; | ||
}): void; | ||
} | ||
@@ -124,0 +129,0 @@ declare class PersistedObject { |
@@ -869,2 +869,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
___broadcast({ room, topic, data }) { | ||
this._send(uuid(), { | ||
op: "broadcast", | ||
"room-id": room, | ||
topic, | ||
data, | ||
}); | ||
} | ||
} | ||
@@ -871,0 +879,0 @@ class Deferred { |
@@ -8,15 +8,5 @@ import { produce } from "immer"; | ||
} | ||
// (XXX): Temporary workaround for missing attrs | ||
// Once we can repro this issue, we can remove this in favor of | ||
// getAttrAsserting; | ||
// -- As an aside, what should happen if we can't find an attr? | ||
function getAttr(attrs, attrId) { | ||
return attrs[attrId]; | ||
} | ||
function getAttrAsserting(attrs, attrId) { | ||
const attr = attrs[attrId]; | ||
if (!attr) | ||
throw new Error(`no such attr: ${attrId}`); | ||
return attr; | ||
} | ||
function getIn(obj, path) { | ||
@@ -183,4 +173,4 @@ return path.reduce((acc, key) => acc && acc[key], obj); | ||
return; | ||
const newTriples = getTriples(store, [id]).filter(([_, aid]) => aid !== id); | ||
delete store.attrs[id]; | ||
const newTriples = getTriples(store, [id]).filter(([_, aid]) => aid !== id); | ||
resetIndexMap(store, newTriples); | ||
@@ -236,3 +226,8 @@ } | ||
const eaTriples = getEATriples(store, e); | ||
const eavTriples = getEAVTriples(store, e).filter(([_, aid]) => !hasEA(getAttrAsserting(store.attrs, aid))); | ||
const eavTriples = getEAVTriples(store, e).filter(([_, aid]) => { | ||
const attr = getAttr(store.attrs, aid); | ||
if (!attr) | ||
return false; | ||
return !hasEA(attr); | ||
}); | ||
return [...eaTriples, ...eavTriples]; | ||
@@ -239,0 +234,0 @@ } |
@@ -122,2 +122,7 @@ export default class Reactor { | ||
___notifyPresenceSubs(roomId: any): void; | ||
___broadcast({ room, topic, data }: { | ||
room: any; | ||
topic: any; | ||
data: any; | ||
}): void; | ||
} | ||
@@ -124,0 +129,0 @@ declare class PersistedObject { |
@@ -897,2 +897,10 @@ "use strict"; | ||
} | ||
___broadcast({ room, topic, data }) { | ||
this._send((0, uuid_1.default)(), { | ||
op: "broadcast", | ||
"room-id": room, | ||
topic, | ||
data, | ||
}); | ||
} | ||
} | ||
@@ -899,0 +907,0 @@ exports.default = Reactor; |
@@ -11,15 +11,5 @@ "use strict"; | ||
} | ||
// (XXX): Temporary workaround for missing attrs | ||
// Once we can repro this issue, we can remove this in favor of | ||
// getAttrAsserting; | ||
// -- As an aside, what should happen if we can't find an attr? | ||
function getAttr(attrs, attrId) { | ||
return attrs[attrId]; | ||
} | ||
function getAttrAsserting(attrs, attrId) { | ||
const attr = attrs[attrId]; | ||
if (!attr) | ||
throw new Error(`no such attr: ${attrId}`); | ||
return attr; | ||
} | ||
function getIn(obj, path) { | ||
@@ -187,4 +177,4 @@ return path.reduce((acc, key) => acc && acc[key], obj); | ||
return; | ||
const newTriples = getTriples(store, [id]).filter(([_, aid]) => aid !== id); | ||
delete store.attrs[id]; | ||
const newTriples = getTriples(store, [id]).filter(([_, aid]) => aid !== id); | ||
resetIndexMap(store, newTriples); | ||
@@ -240,3 +230,8 @@ } | ||
const eaTriples = getEATriples(store, e); | ||
const eavTriples = getEAVTriples(store, e).filter(([_, aid]) => !hasEA(getAttrAsserting(store.attrs, aid))); | ||
const eavTriples = getEAVTriples(store, e).filter(([_, aid]) => { | ||
const attr = getAttr(store.attrs, aid); | ||
if (!attr) | ||
return false; | ||
return !hasEA(attr); | ||
}); | ||
return [...eaTriples, ...eavTriples]; | ||
@@ -243,0 +238,0 @@ } |
{ | ||
"name": "@instantdb/core", | ||
"version": "0.8.2", | ||
"version": "0.8.3", | ||
"description": "Instant's core local abstraction", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -1002,2 +1002,11 @@ import log from "./utils/log"; | ||
} | ||
___broadcast({ room, topic, data }) { | ||
this._send(uuid(), { | ||
op: "broadcast", | ||
"room-id": room, | ||
topic, | ||
data, | ||
}); | ||
} | ||
} | ||
@@ -1004,0 +1013,0 @@ |
@@ -11,6 +11,2 @@ import { produce } from "immer"; | ||
// (XXX): Temporary workaround for missing attrs | ||
// Once we can repro this issue, we can remove this in favor of | ||
// getAttrAsserting; | ||
// -- As an aside, what should happen if we can't find an attr? | ||
function getAttr(attrs, attrId) { | ||
@@ -20,8 +16,2 @@ return attrs[attrId]; | ||
function getAttrAsserting(attrs, attrId) { | ||
const attr = attrs[attrId]; | ||
if (!attr) throw new Error(`no such attr: ${attrId}`); | ||
return attr; | ||
} | ||
function getIn(obj, path) { | ||
@@ -114,23 +104,23 @@ return path.reduce((acc, key) => acc && acc[key], obj); | ||
/** | ||
* (XXX) | ||
* Two hacks here, for generating a `createdAt` | ||
* | ||
* 1. We multiply Date.now() by 10, to make sure that | ||
* `createdAt` is always greater than anything the server | ||
* could return | ||
* | ||
* We do this because right now we know we _only_ insert | ||
* triples as optimistic updates. | ||
* | ||
* 2. We increment by `_seed`, to make sure there are no | ||
* two triples with the same `createdAt`. This is | ||
* done to make tests more predictable. | ||
* | ||
* We may need to rethink this. Because we * 10, we can't | ||
* use this value as an _actual_ `createdAt` timestamp. | ||
* Eventually we may want too though; For example, we could | ||
* use `createdAt` for each triple, to infer a `createdAt` and | ||
* `updatedAt` value for each object. | ||
*/ | ||
/** | ||
* (XXX) | ||
* Two hacks here, for generating a `createdAt` | ||
* | ||
* 1. We multiply Date.now() by 10, to make sure that | ||
* `createdAt` is always greater than anything the server | ||
* could return | ||
* | ||
* We do this because right now we know we _only_ insert | ||
* triples as optimistic updates. | ||
* | ||
* 2. We increment by `_seed`, to make sure there are no | ||
* two triples with the same `createdAt`. This is | ||
* done to make tests more predictable. | ||
* | ||
* We may need to rethink this. Because we * 10, we can't | ||
* use this value as an _actual_ `createdAt` timestamp. | ||
* Eventually we may want too though; For example, we could | ||
* use `createdAt` for each triple, to infer a `createdAt` and | ||
* `updatedAt` value for each object. | ||
*/ | ||
return createdAt || Date.now() * 10 + _seed++; | ||
@@ -204,4 +194,4 @@ } | ||
if (!store.attrs[id]) return; | ||
const newTriples = getTriples(store, [id]).filter(([_, aid]) => aid !== id); | ||
delete store.attrs[id]; | ||
const newTriples = getTriples(store, [id]).filter(([_, aid]) => aid !== id); | ||
resetIndexMap(store, newTriples); | ||
@@ -261,5 +251,7 @@ } | ||
const eaTriples = getEATriples(store, e); | ||
const eavTriples = getEAVTriples(store, e).filter( | ||
([_, aid]) => !hasEA(getAttrAsserting(store.attrs, aid)), | ||
); | ||
const eavTriples = getEAVTriples(store, e).filter(([_, aid]) => { | ||
const attr = getAttr(store.attrs, aid); | ||
if (!attr) return false; | ||
return !hasEA(attr); | ||
}); | ||
return [...eaTriples, ...eavTriples]; | ||
@@ -266,0 +258,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
32923
1444228