đ§° @exposition/sdk
Utils of the @exposition library, to create and update the state in a non-mutating way.
Install
pnpm add -D @exposition/sdk
yarn add -D @exposition/sdk
npm install -D @exposition/sdk
createExpositionState
Create an Exposition state with all necessary data. đŽ
- Cast the config
as constto get full type support. (as seen on line 8) ⨠- The first
optionsitem will be set as theinitialValueof theScenario
Â
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.
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)
updateExpositionValues
Update the values of the given ExpositionState and create a new ExpositionState state. đ
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 âī¸' }
getExpositionValues
Extract the current values from a given ExpositionState. đ
const expositionState = createExpositionState({
base: {
options: [
'đ Rice - Cool',
'đ Pasta - Mama Mia',
],
},
})
getExpositionValues(expositionState) // { base: "đ Rice - Cool" }
getInitialExpositionValues
Extract the initials values from a given ExpositionState. đĻ
const expositionState = createExpositionState({
progress: {
options: [
'đ Small',
'đĻ Big',
],
},
})
const updatedExposition = updateExpositionValues(expositionState, { progress: 'đĻ Big' })
getInitialExpositionValues(updatedExposition) // { progress: "đ Small" }
resetExpositionValues
Reset the values of a given ExpositionState to their initialValue. â°
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 đ" }