@insertish/mutable
Advanced tools
Comparing version
@@ -20,2 +20,3 @@ import { Collection } from '@insertish/zangodb'; | ||
set(state: T): void; | ||
setOverride(state: T): void; | ||
patch(id: string, state: Partial<T>): void; | ||
@@ -22,0 +23,0 @@ delete(_id: string): void; |
@@ -71,2 +71,17 @@ "use strict"; | ||
} | ||
setOverride(state) { | ||
var _a; | ||
let existing = this.getMutable(state._id); | ||
if (existing) { | ||
this.map[state._id] = new Proxy(state, this.proxyHandler); | ||
this.emit('update', state._id); | ||
(_a = this.collection) === null || _a === void 0 ? void 0 : _a.update({ _id: state._id }, { | ||
$unset: Object.keys(existing).filter(x => x !== '_id'), | ||
$set: Object.assign({}, state) | ||
}); | ||
} | ||
else { | ||
this.create(state); | ||
} | ||
} | ||
patch(id, state) { | ||
@@ -73,0 +88,0 @@ let item = this.map[id]; |
{ | ||
"name": "@insertish/mutable", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Mutable object utilities.", | ||
@@ -28,3 +28,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@insertish/zangodb": "1.0.11", | ||
"@insertish/zangodb": "^1.0.12", | ||
"eventemitter3": "^4.0.7", | ||
@@ -31,0 +31,0 @@ "lodash.isequal": "^4.5.0" |
@@ -0,1 +1,3 @@ | ||
 | ||
### Why? | ||
@@ -18,3 +20,3 @@ | ||
```typescript | ||
import { MutableMap } from 'mutable.js'; | ||
import { MutableMap } from '@insertish/mutable'; | ||
@@ -21,0 +23,0 @@ type User = { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
17334
7.76%184
9.52%72
2.86%+ Added
- Removed
Updated