minitel.ts
Version:
A port to typescript and extension of https://github.com/cquest/pynitel
13 lines (12 loc) • 404 B
JavaScript
export default function MinitelTSState({ initial = {}, name = 'state' } = {}) {
let internalState = initial;
const setState = (newState) => {
internalState = Object.assign(Object.assign({}, internalState), newState);
};
return {
get [name]() {
return internalState;
},
[`set${name.charAt(0).toUpperCase() + name.slice(1)}`]: setState,
};
}