Functions and other utils to work with the exposition library
npm install @exposition/sdkUtils of the @exposition library,
to create and update the state in a non-mutating way.
``sh`
pnpm add -D @exposition/sdk
`sh`
yarn add -D @exposition/sdk
`sh`
npm install -D @exposition/sdk
Create an Exposition state with all necessary data. đŽ
- Cast the config as const to get full type support. _(as seen on line 8)_ â¨options
- The first item will be set as the initialValue of the Scenario
`ts{16}
import { createExpositionState } from '@exposition/sdk'
// ⨠Cast the input config as const to get full type support`
const expositionState = createExpositionState({
auth: {
options: ['valid â
', 'deny â']
},
user: {
age: {
options: ['under 18 đŖ', '18 đ', 'over 18 đĻ']
},
avatar: {
options: ['no avatar đŦ', 'image đ¤ŗ']
}
}
} as const)
You can also create subgroups by defining further elements inside the configuration file as you can see in this example.
_The last option MUST have an options key for internal type inference._
`ts
import { createExpositionState } from '@exposition/sdk'
const expositionState = createExpositionState({
user: {
age: {
options: ['under 18 đŖ', '18 đ', 'over 18 đĻ']
},
avatar: {
options: ['no avatar đŦ', 'image đ¤ŗ']
},
auth: {
options: ['valid â
', 'deny â']
},
rights: {
users: {
create: {
options: ['yes â
', 'no â']
},
read: {
options: ['yes â
', 'no â']
},
update: {
options: ['yes â
', 'no â']
},
delete: {
options: ['yes â
', 'no â']
}
}
}
}
} as const)
`
Update the values of the given ExpositionState and create a new ExpositionState state. đ
`ts
const expositionState = createExpositionState({
autobot: { options: ['Optimus Prime đ', 'Bumblebee đ'] },
decepticon: { options: ['Megatron âī¸', 'Starscream đŠī¸'] },
} as const)
const updatedExposition = updateExpositionValues(
expositionState,
{ autobot: 'Bumblebee đ' }
)
getExpositionValues(updatedExposition)
// { autobot: 'Bumblebee đ', decepticon: 'Megatron âī¸' }
`
Extract the current values from a given ExpositionState. đ
`ts
const expositionState = createExpositionState({
base: {
options: [
'đ Rice - Cool',
'đ Pasta - Mama Mia',
],
},
})
getExpositionValues(expositionState) // { base: "đ Rice - Cool" }
`
Extract the initials values from a given ExpositionState. đĻ
`ts
const expositionState = createExpositionState({
progress: {
options: [
'đ Small',
'đĻ Big',
],
},
})
const updatedExposition = updateExpositionValues(expositionState, { progress: 'đĻ Big' })
getInitialExpositionValues(updatedExposition) // { progress: "đ Small" }
`
Reset the values of a given ExpositionState to their initialValue. â°
`ts
const expositionState = createExpositionState({
character: { options: ['Dio đ', 'JoJo đ'] },
} as const)
const updatedExposition = updateExpositionValues(
expositionState,
{ character: 'JoJo đ' }
)
getExpositionValues(updatedExposition) // { character: "JoJo đ" }
const revertedExposition = resetExpositionValues(updatedExposition)
getExpositionValues(revertedExposition) // { character: "Dio đ" }
``