diff --git a/src/base.js b/src/base.js index 9449858..6e38d43 100644 --- a/src/base.js +++ b/src/base.js @@ -12,12 +12,11 @@ import { const {Iterator} = Iterable; const NOT_SET = {}; // Sentinel value -function Base(rootData, keyPath, updater, deref, size) { +function Base(rootData, keyPath, store, size) { this.size = size; this._rootData = rootData; this._keyPath = keyPath; - this._updater = updater; - this._deref = deref; + this._store = store; } Base.prototype = { diff --git a/src/cursor.js b/src/cursor.js index 0cc90ba..4e57924 100644 --- a/src/cursor.js +++ b/src/cursor.js @@ -25,7 +25,7 @@ function cursorFrom(data, keyPath, onChange) { atom.watch(onChange); } - return makeCursor(data, keyPath, atom.write.bind(atom), atom.read); + return makeCursor(data, keyPath, atom); } exports.from = cursorFrom; diff --git a/src/utils.js b/src/utils.js index 7432ed7..c3ff7ec 100644 --- a/src/utils.js +++ b/src/utils.js @@ -23,13 +23,13 @@ export function defineRecordProperties(cursor, value) { } } -export function makeCursor(rootData, keyPath, updater, deref, value) { +export function makeCursor(rootData, keyPath, store, value) { if (arguments.length < 5) { value = rootData.getIn(keyPath); } const size = value && value.size; const Cursor = Iterable.isIndexed(value) ? IndexedCursor : KeyedCursor; - const cursor = new Cursor(rootData, keyPath, updater, deref, size); + const cursor = new Cursor(rootData, keyPath, store, size); if (value instanceof Record) { defineRecordProperties(cursor, value); @@ -65,15 +65,13 @@ export function subCursor(cursor, keyPath, value) { return makeCursor( // call without value cursor._rootData, newKeyPath(cursor._keyPath, keyPath), - cursor._updater, - cursor._deref + cursor._store ); } return makeCursor( cursor._rootData, newKeyPath(cursor._keyPath, keyPath), - cursor._updater, - cursor._deref, + cursor._store, value ); } @@ -85,7 +83,7 @@ export function updateCursor(cursor, changeFn) { deepChange ? Map() : undefined, changeFn ); - return makeCursor(cursor._updater(updateFn), cursor._keyPath, cursor._updater, cursor._deref); + return makeCursor(cursor._store.write(updateFn), cursor._keyPath, cursor._store); } export function wrappedValue(cursor, keyPath, value) {