So I am looking to add an undo to the Sudoku app and was going to use the store.
I initially tried to use the old version (AU1) and it wasn’t getting state initialized.
I tied to pull the @aurelia/store and it appears to just be a placeholder project atm.
Is there an example of using the the older store plugin using the newer aurelia.register
Thanks for the suggestion.
I did try that and in looking at the node-modules directory after installation it appeared to just be the placeholder project as well. I tried looking through the different branches and packages and couldn’t find anything that (to me at least) appeared relevant.
Hey there, the reason for no v2 version is that Corona and my paternity leave pushed that backwards
I’ll be gathering some inputs and coming back to finishing the tests next week. There is a branch called aurelia-store where already most of the work is done thanks to @dwaynecharrington. I’ve updated it to be feature-equal with v1 and hopefully soon should have a deployable version.
I’ll let you guys know here once it’s published as I’m definitely looking forward to some help testing it out in your projects
Thanks for the update. I haven’t pushed or tagged folks because I figured those in the know were well aware and it was just a time available thing. You guys rock.
Work is progressing, slowly but steady. I had to learn tons of stuff about how v2 works and admitted there will be a few minor breaking changes. On the other hand issues we experienced with testing components using connectTo or other globals such as window are going to be eliminated. Also the registration process is now going to be typesafe whereas in v1 you had to know what to provide to the plugin instantiation API.
Overall I must say I’m super excited how things go. It will take a while but I’m sure people are going to love it.
import { inject } from 'aurelia';
import { connectTo, Store } from '@aurelia/store-v1';
import { ipcRenderer } from 'electron';
import { IAppState } from './state/empty-state';
import { IShortcutResources } from '../shared/models/shortcut-resources.dto';
import { setShortcutResources } from '../renderer/state/actions/shortcut-resource-actions';
@inject(Store)
@connectTo()
export class EpicApp {
public loading = false;
public errorMessage?: string | null;
private store: Store<IAppState>;
constructor(store: Store<IAppState>) {
this.store = store;
store.registerAction('Set Shortcut Resources', setShortcutResources);
}
public attached(): void {
this.loading = true;
this.loadEpicResources();
}
public async loadEpicResources(): Promise<void> {
try {
const shortcutResources = (await ipcRenderer.invoke(
'shortcut-resources-load'
)) as IShortcutResources;
this.store.dispatch(setShortcutResources, shortcutResources);
} catch (error: unknown) {
this.errorMessage = (error as Error).message;
} finally {
this.loading = false;
}
}
}
…I get the following typing error on line store.registerAction('Set Shortcut Resources', setShortcutResources);:
Argument of type '(state: IAppState, model: IShortcutResources) => IAppState' is not assignable to parameter of type 'Reducer<IAppState, unknown[]>'.
Types of parameters 'model' and 'params' are incompatible.
Type 'unknown' is not assignable to type 'IShortcutResources'.ts(2345)
hmm thats interesting. what TS version are you using? also it seems this is an electron app and you have types shared. are they part of the same project just renderer/main shared?
exactly, and I was under the impression this should work. could you give the following a try? change the nodemodules source of the plugin to use any in that position just so we verify its the unknown vs any
No juice, same error. I had a hard time believing that, and went so far as to restart the VSCode typescript server, and then VSCode itself when that didn’t work. Same error from command line running webpack.
For now I’m working around by casting my action to any and all functions as expected: