Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store.reset('options.items') not working #242

Open
pierretusseau opened this issue Nov 29, 2022 · 2 comments
Open

store.reset('options.items') not working #242

pierretusseau opened this issue Nov 29, 2022 · 2 comments

Comments

@pierretusseau
Copy link

pierretusseau commented Nov 29, 2022

Hello,

I've got defaults setup as such :

{
  "initialized": false,
  ...
  "options": {
    "admin": {
      "darkmode": true,
      ...
    },
    "items": {
      "preview": false,
      ...
    }
  }
}

I'm looking to reset only "options": {"items": { ... }} in my store but I couldn't find how to do it.

If I do a store.reset('options') all of my store options get correctly cleared, but also any other data inside of it (like admin).

I feel like reset(...keys) doesn't understand the dot notation, is there something I'm missing, or should I split my store into something like :

{
  ...,
  "adminOptions": {
    "darkmode": true,
    ...
  },
  "itemsOptions": {
    "preview": false,
    ...
  }
}
@ProMahmudul
Copy link

@pierretusseau Have you found solutions? I also want to know this.

@kashamalasha
Copy link

I found a workaround for this problem.
At first, define the schema before creating a store:

const schema = {
  "options": {
    "type": "object",
    "properties": {
      "items": {
        "type": "object",
        "properties": {
          "preview": {
            "type": "boolean",
            "default": false
          }
        },
        "required": ["preview"]
      }
    },
    "required": ["items"]
  }
};

const store = new Store({ schema });

Then you can use this to resets all keys within the options.items to default values according to the json schema values.
store.set(`options.items`, {});

Unfortunately, the method store.reset(key) also doesn't work for me properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants