Skip to main content
Solved

How do I use GlobalConfig.setPathsAsync?

  • January 26, 2020
  • 3 replies
  • 24 views

Forum|alt.badge.img+14

Hi there,

Tried different ways, without luck as of yet. It’s lacking documentation and I also couldn’t find an example in any of the block examples.

Thanks,
Ronen

Best answer by Kasra

Hi Ronen,

globalConfig.setPathsAsync takes an array of update objects, e.g.

await globalConfig.setPathsAsync([
  {path: ['a', 'b'], value: 1},
  {path: ['c'], value: 2},
])

Would result in the following data in globalConfig:

{
  a: {
    b: 1,
  },
  c: 2
}

Hope this helps! We’ll look into adding an example in the docs for this, thanks for pointing it out :slightly_smiling_face:

3 replies

Forum|alt.badge.img+4
  • Inspiring
  • 192 replies
  • Answer
  • January 26, 2020

Hi Ronen,

globalConfig.setPathsAsync takes an array of update objects, e.g.

await globalConfig.setPathsAsync([
  {path: ['a', 'b'], value: 1},
  {path: ['c'], value: 2},
])

Would result in the following data in globalConfig:

{
  a: {
    b: 1,
  },
  c: 2
}

Hope this helps! We’ll look into adding an example in the docs for this, thanks for pointing it out :slightly_smiling_face:


Forum|alt.badge.img+14
  • Author
  • Inspiring
  • 47 replies
  • January 26, 2020

Yes, definitely, thanks :pray: Related question, on how to use setAsync (an example for that in the docs would also help :slightly_smiling_face: ), right now, I’m using it as:

globalConfig.setAsync('c', 2)

If I want to create a key in a sub doc, I just:

globalConfig.setAsync(['a', 'b'], 1)

Correct?


Forum|alt.badge.img+4
  • Inspiring
  • 192 replies
  • January 26, 2020

Yep! globalConfig paths can be an array of keys. It’ll create the intermediate objects if needed automatically.