Skip to content

Commit

Permalink
Update shared-constants.mdx to explicitly call out the default value …
Browse files Browse the repository at this point in the history
…for dataPath

The docs used the word "enable" that made us think that if a `dataPath` isnt provided, the constants will not be overridable through content. However, looking at the code thats not true

https://github.com/player-ui/player/blob/7e2c1a691ea8e0aae1f2c412d145dcb4749d7164/plugins/shared-constants/core/src/index.ts#L45
  • Loading branch information
A1shK authored Feb 3, 2025
1 parent 4b4df1f commit b7656ed
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const constantsPlugin = new ConstantsPlugin({
prop2: "B",
},
namespace: "constants",
dataPath: "data.constants",
dataPath: "data.props",
});

const player = new Player({
Expand All @@ -42,12 +42,12 @@ constantsPlugin.getConstants("prop1"); // 'A'

### Overriding Values in Content

The `dataPath` configuration option enables content to override specific values for a particular flow:
The `dataPath` configuration option allows content to override specific values for a particular flow:

```json
{
"data": {
"constants": {
"props": {
"prop1": "B"
}
}
Expand All @@ -56,6 +56,17 @@ The `dataPath` configuration option enables content to override specific values

using a similar query for `prop1`, the value in the content takes precidence and would return `B`.

If no `dataPath` is defined, then it defaults to `constants` and you can still do this
```json
{
"data": {
"constants": {
"prop1": "B"
}
}
}
```

### Fallback Values

Any query can also specify an optional _default_ value to return:
Expand Down

0 comments on commit b7656ed

Please sign in to comment.