Comparing version 2.0.0-alpha.1 to 2.0.0-alpha.2
{ | ||
"name": "valtio", | ||
"private": false, | ||
"version": "2.0.0-alpha.1", | ||
"version": "2.0.0-alpha.2", | ||
"publishConfig": { | ||
@@ -6,0 +6,0 @@ "tag": "next" |
@@ -317,3 +317,3 @@ <img src="logo.svg" alt="valtio"> | ||
```js | ||
import { proxyWithHistory } from 'valtio/utils' | ||
import { proxyWithHistory } from 'valtio-history' | ||
@@ -320,0 +320,0 @@ const state = proxyWithHistory({ count: 0 }) |
@@ -5,4 +5,3 @@ export { subscribeKey } from './utils/subscribeKey'; | ||
export { deepClone } from './utils/deepClone'; | ||
export { proxyWithHistory } from './utils/proxyWithHistory'; | ||
export { proxySet } from './utils/proxySet'; | ||
export { proxyMap } from './utils/proxyMap'; |
@@ -588,52 +588,2 @@ 'use strict'; | ||
function proxyWithHistory(initialValue, skipSubscribe) { | ||
if (skipSubscribe === void 0) { | ||
skipSubscribe = false; | ||
} | ||
var proxyObject = vanilla.proxy({ | ||
value: initialValue, | ||
history: vanilla.ref({ | ||
wip: undefined, | ||
snapshots: [], | ||
index: -1 | ||
}), | ||
clone: deepClone, | ||
canUndo: function canUndo() { | ||
return proxyObject.history.index > 0; | ||
}, | ||
undo: function undo() { | ||
if (proxyObject.canUndo()) { | ||
proxyObject.value = proxyObject.history.wip = proxyObject.clone(proxyObject.history.snapshots[--proxyObject.history.index]); | ||
} | ||
}, | ||
canRedo: function canRedo() { | ||
return proxyObject.history.index < proxyObject.history.snapshots.length - 1; | ||
}, | ||
redo: function redo() { | ||
if (proxyObject.canRedo()) { | ||
proxyObject.value = proxyObject.history.wip = proxyObject.clone(proxyObject.history.snapshots[++proxyObject.history.index]); | ||
} | ||
}, | ||
saveHistory: function saveHistory() { | ||
proxyObject.history.snapshots.splice(proxyObject.history.index + 1); | ||
proxyObject.history.snapshots.push(vanilla.snapshot(proxyObject).value); | ||
++proxyObject.history.index; | ||
}, | ||
subscribe: function subscribe() { | ||
return vanilla.subscribe(proxyObject, function (ops) { | ||
if (ops.every(function (op) { | ||
return op[1][0] === 'value' && (op[0] !== 'set' || op[2] !== proxyObject.history.wip); | ||
})) { | ||
proxyObject.saveHistory(); | ||
} | ||
}); | ||
} | ||
}); | ||
proxyObject.saveHistory(); | ||
if (!skipSubscribe) { | ||
proxyObject.subscribe(); | ||
} | ||
return proxyObject; | ||
} | ||
function proxySet(initialValues) { | ||
@@ -792,4 +742,3 @@ var _proxy; | ||
exports.proxySet = proxySet; | ||
exports.proxyWithHistory = proxyWithHistory; | ||
exports.subscribeKey = subscribeKey; | ||
exports.watch = watch; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
90993
42
2018