Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
12 changes: 5 additions & 7 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
);
}
Expand All @@ -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) {
Expand Down