quarrant/mobx-persist-store

Question: adding a custom variable name instead of harcoded properties name

alaa-paramount opened this issue · 3 comments

hi guys,

I'm facing the following situation:

testVar = "abc";

makePersistable(
    this,
    {
	    properties: ['testVar'],
	    // rest of stuff
    }
);

I'm trying to pass a variable name to 'properties', but it's not working,
also, I've tried to do it like the following code but it didn't work:
properties: [Object.keys(this.testVar)[0] as keyof this],

my goal is to not hardcode strings inside properties[]
any suggestions?

Can you add an https://codesandbox.io/ example of what you are trying to do and I can look at it.

Thanks @codeBelt,

here's the codesnadbox:
https://codesandbox.io/p/sandbox/todostore-ts-sepdzu?file=%2Fstore%2FTodoStore.ts&selection=%5B%7B%22endColumn%22%3A52%2C%22endLineNumber%22%3A22%2C%22startColumn%22%3A52%2C%22startLineNumber%22%3A22%7D%5D

file: TodoStore.ts
scroll to line 21:
properties: ["activeNote"]

my goal is to make it work with variable, something like this:
properties: [this.activeNote]

ThaJay commented

@alaa-ananey

    makePersistable(this, {
      name: 'ChangeAddressStore',
      properties: Object.keys(this) as (keyof this)[]
    })