Then I provide this object to mobx-persist-store during initial configuration:
import { makeAutoObservable } from "mobx";
import { makePersistable } from "mobx-persist-store";
import Todo from "../entities/Todo";
import localForageEntityStorageController from "./LocalForageEntityStorageController";
class TodoStore {
public todos: Todo[] = [];
public constructor() {
makeAutoObservable(this);
makePersistable(
this,
{
name: "Todos",
properties: ["todos"],
storage: localForageEntityStorageController,
stringify: true
},
{
delay: 200
}
);
}
}
export default new TodoStore();
You can see how I have to disable the @typescript-eslint/promise-function-async lint rule. This is because mobx-persist-store will error if I pass anonymous functions for my StorageController methods. This is inconvenient as it forces me to use the legacy then syntax with promises.
The following internal function (and perhaps callers) could be modified to support asynchronous functions:
I created a simple object that conforms to
StorageController
:Then I provide this object to mobx-persist-store during initial configuration:
You can see how I have to disable the
@typescript-eslint/promise-function-async
lint rule. This is because mobx-persist-store will error if I pass anonymous functions for myStorageController
methods. This is inconvenient as it forces me to use the legacythen
syntax with promises.The following internal function (and perhaps callers) could be modified to support asynchronous functions:
https://github.com/quarrant/mobx-persist-store/blob/25bab48a8c8ef11dff0466d3f1e3295c0e8e9acc/src/utils.ts#L31-L33
[object AsyncFunction]
is what is reported (at least in Firefox) when I pass anonymous functions.