@instantdb/core
Advanced tools
Comparing version 0.7.11 to 0.7.12
@@ -525,10 +525,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
optimisticAttrs() { | ||
const pendingAttrs = [...this.pendingMutations.currentValue.values()] // hack due to Map() | ||
.flatMap((x) => x["tx-steps"]) | ||
.filter(([action, ..._args]) => action === "add-attr") | ||
.map(([_action, attr]) => attr); | ||
return pendingAttrs.reduce((acc, attr) => { | ||
acc[attr.id] = attr; | ||
return acc; | ||
}, Object.assign({}, this.attrs)); | ||
var _a; | ||
const pendingMutationSteps = [ | ||
...this.pendingMutations.currentValue.values(), | ||
] // hack due to Map() | ||
.flatMap((x) => x["tx-steps"]); | ||
const deletedAttrIds = new Set(pendingMutationSteps | ||
.filter(([action, _attr]) => action === "delete-attr") | ||
.map(([_action, id]) => id)); | ||
const pendingAttrs = []; | ||
for (const [_action, attr] of pendingMutationSteps) { | ||
if (_action === "add-attr") { | ||
pendingAttrs.push(attr); | ||
} | ||
else if (_action === "update-attr" && | ||
attr.id && | ||
((_a = this.attrs) === null || _a === void 0 ? void 0 : _a[attr.id])) { | ||
const fullAttr = Object.assign(Object.assign({}, this.attrs[attr.id]), attr); | ||
pendingAttrs.push(fullAttr); | ||
} | ||
} | ||
const attrsWithoutDeleted = [ | ||
...Object.values(this.attrs), | ||
...pendingAttrs, | ||
].filter((a) => !deletedAttrIds.has(a.id)); | ||
const attrsRecord = Object.fromEntries(attrsWithoutDeleted.map((a) => [a.id, a])); | ||
return attrsRecord; | ||
} | ||
@@ -683,3 +701,4 @@ /** Runs instaql on a query and a store */ | ||
return; | ||
this.attrsCbs.forEach((cb) => cb(this.optimisticAttrs())); | ||
const oas = this.optimisticAttrs(); | ||
this.attrsCbs.forEach((cb) => cb(oas)); | ||
} | ||
@@ -686,0 +705,0 @@ setCurrentUser(user) { |
@@ -553,10 +553,28 @@ "use strict"; | ||
optimisticAttrs() { | ||
const pendingAttrs = [...this.pendingMutations.currentValue.values()] // hack due to Map() | ||
.flatMap((x) => x["tx-steps"]) | ||
.filter(([action, ..._args]) => action === "add-attr") | ||
.map(([_action, attr]) => attr); | ||
return pendingAttrs.reduce((acc, attr) => { | ||
acc[attr.id] = attr; | ||
return acc; | ||
}, Object.assign({}, this.attrs)); | ||
var _a; | ||
const pendingMutationSteps = [ | ||
...this.pendingMutations.currentValue.values(), | ||
] // hack due to Map() | ||
.flatMap((x) => x["tx-steps"]); | ||
const deletedAttrIds = new Set(pendingMutationSteps | ||
.filter(([action, _attr]) => action === "delete-attr") | ||
.map(([_action, id]) => id)); | ||
const pendingAttrs = []; | ||
for (const [_action, attr] of pendingMutationSteps) { | ||
if (_action === "add-attr") { | ||
pendingAttrs.push(attr); | ||
} | ||
else if (_action === "update-attr" && | ||
attr.id && | ||
((_a = this.attrs) === null || _a === void 0 ? void 0 : _a[attr.id])) { | ||
const fullAttr = Object.assign(Object.assign({}, this.attrs[attr.id]), attr); | ||
pendingAttrs.push(fullAttr); | ||
} | ||
} | ||
const attrsWithoutDeleted = [ | ||
...Object.values(this.attrs), | ||
...pendingAttrs, | ||
].filter((a) => !deletedAttrIds.has(a.id)); | ||
const attrsRecord = Object.fromEntries(attrsWithoutDeleted.map((a) => [a.id, a])); | ||
return attrsRecord; | ||
} | ||
@@ -711,3 +729,4 @@ /** Runs instaql on a query and a store */ | ||
return; | ||
this.attrsCbs.forEach((cb) => cb(this.optimisticAttrs())); | ||
const oas = this.optimisticAttrs(); | ||
this.attrsCbs.forEach((cb) => cb(oas)); | ||
} | ||
@@ -714,0 +733,0 @@ setCurrentUser(user) { |
{ | ||
"name": "@instantdb/core", | ||
"version": "0.7.11", | ||
"version": "0.7.12", | ||
"description": "Instant's core local abstraction", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -515,13 +515,37 @@ import log from "./utils/log"; | ||
optimisticAttrs() { | ||
const pendingAttrs = [...this.pendingMutations.currentValue.values()] // hack due to Map() | ||
.flatMap((x) => x["tx-steps"]) | ||
.filter(([action, ..._args]) => action === "add-attr") | ||
.map(([_action, attr]) => attr); | ||
return pendingAttrs.reduce( | ||
(acc, attr) => { | ||
acc[attr.id] = attr; | ||
return acc; | ||
}, | ||
{ ...this.attrs }, | ||
const pendingMutationSteps = [ | ||
...this.pendingMutations.currentValue.values(), | ||
] // hack due to Map() | ||
.flatMap((x) => x["tx-steps"]); | ||
const deletedAttrIds = new Set( | ||
pendingMutationSteps | ||
.filter(([action, _attr]) => action === "delete-attr") | ||
.map(([_action, id]) => id), | ||
); | ||
const pendingAttrs = []; | ||
for (const [_action, attr] of pendingMutationSteps) { | ||
if (_action === "add-attr") { | ||
pendingAttrs.push(attr); | ||
} else if ( | ||
_action === "update-attr" && | ||
attr.id && | ||
this.attrs?.[attr.id] | ||
) { | ||
const fullAttr = { ...this.attrs[attr.id], ...attr }; | ||
pendingAttrs.push(fullAttr); | ||
} | ||
} | ||
const attrsWithoutDeleted = [ | ||
...Object.values(this.attrs), | ||
...pendingAttrs, | ||
].filter((a) => !deletedAttrIds.has(a.id)); | ||
const attrsRecord = Object.fromEntries( | ||
attrsWithoutDeleted.map((a) => [a.id, a]), | ||
); | ||
return attrsRecord; | ||
} | ||
@@ -789,3 +813,4 @@ | ||
if (!this.attrs) return; | ||
this.attrsCbs.forEach((cb) => cb(this.optimisticAttrs())); | ||
const oas = this.optimisticAttrs(); | ||
this.attrsCbs.forEach((cb) => cb(oas)); | ||
} | ||
@@ -792,0 +817,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
1423931
32473