-
Notifications
You must be signed in to change notification settings - Fork 78
Closed
Labels
bugSomething isn't workingSomething isn't workingneeds back-portThe fix requires back porting to one or more previous major versionsThe fix requires back porting to one or more previous major versionsnextIssue/Pull Request for the next major versionIssue/Pull Request for the next major version
Description
Bug
Using of number-like strings (eg. "0ab1-f385" or "123") or strings starting with a number ("1alice") in an index structure in the store does not work properly. With such strings no index is created. The store converts the structure to array.
Package Version: 2.0.0 - 5.0.2
Code
import { createCommandFactory, createProcess } from "@dojo/framework/stores/process";
import { replace } from "@dojo/framework/stores/state/operations";
import Store from "@dojo/framework/stores/Store";
import { v, w } from "@dojo/framework/widget-core/d";
import Registry from "@dojo/framework/widget-core/Registry";
import renderer from "@dojo/framework/widget-core/vdom";
import { WidgetBase } from "@dojo/framework/widget-core/WidgetBase";
interface State {
data: IndexedData;
}
interface IndexedData {
[index: string]: DataEntry;
}
interface DataEntry {
id: string;
name: string;
}
const createCommand = createCommandFactory<State>();
const setDataEntryCommand = createCommand<DataEntry>(({ path, payload }) => [replace(path("data", payload.id), payload)]);
export const setDataEntryProcess = createProcess("setDataEntryProcess", [setDataEntryCommand]);
class App extends WidgetBase {
protected render() {
return v("div", [
v(
"button",
{
onclick: () => {
setDataEntryProcess(store)({ id: "0asd-dsds", name: "Bob" });
//@ts-ignore
console.log(store._state);
}
},
["0asd-dsds"]
),
v(
"button",
{
onclick: () => {
setDataEntryProcess(store)({ id: "Alice", name: "Alice" });
//@ts-ignore
console.log(store._state);
}
},
["Alice"]
),
v(
"button",
{
onclick: () => {
setDataEntryProcess(store)({ id: "50070023", name: "Sam" });
//@ts-ignore
console.log(store._state);
}
},
["50070023"]
)
]);
}
}
export const store = new Store<State>();
const registry = new Registry();
const r = renderer(() => w(App, {}));
r.mount({ registry });Expected behavior:
data: {
"0asd-dsds" : {id: "0asd-dsds", name: "Bob"},
"50070023" : {id: "50070023", name: "Sam"},
"Alice" : {id: "Alice", name: "Alice"},
}Actual behavior:
data: [
{id: "50070023", name: "Sam"},
{id: "Alice", name: "Alice"},
]Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingneeds back-portThe fix requires back porting to one or more previous major versionsThe fix requires back porting to one or more previous major versionsnextIssue/Pull Request for the next major versionIssue/Pull Request for the next major version