Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/stores/state/Pointer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function walk(segments: string[], object: any, clone = true, continueOnUn
segment = String(pointerTarget.target.length - 1);
}
if (index + 1 < segments.length) {
const nextSegment = segments[index + 1];
const nextSegment: any = segments[index + 1];
let target = pointerTarget.target[segment];

if (target === undefined && !continueOnUndefined) {
Expand All @@ -43,7 +43,7 @@ export function walk(segments: string[], object: any, clone = true, continueOnUn
target = [...target];
} else if (typeof target === 'object') {
target = { ...target };
} else if (isNaN(parseInt(nextSegment, 0))) {
} else if (isNaN(nextSegment) || isNaN(parseInt(nextSegment, 0))) {
target = {};
} else {
target = [];
Expand Down
14 changes: 13 additions & 1 deletion tests/stores/unit/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
createCallbackDecorator
} from '../../../src/stores/process';
import { Store } from '../../../src/stores/Store';
import { replace } from '../../../src/stores/state/operations';
import { replace, add } from '../../../src/stores/state/operations';

let store: Store;
let promises: Promise<any>[] = [];
Expand Down Expand Up @@ -169,6 +169,18 @@ describe('process', () => {
assert.equal(typeof command, 'function');
});

it('should add object by integer like index key', () => {
const id = '3fe3c6d3-15e1-4d77-886f-daeb0ed63458';
const createCommand = createCommandFactory<any>();
const command = createCommand(({ get, path, payload }) => {
return [add(path('test', id), { foo: 'bar' })];
});
const process = createProcess('test', [command]);
const executor = process(store);
executor({});
assert.deepEqual(store.get(store.path('test')), { [id]: { foo: 'bar' } });
});

it('can type payload that extends an object', () => {
const createCommandOne = createCommandFactory<any, { foo: string }>();
const createCommandTwo = createCommandFactory<any, { bar: string }>();
Expand Down