Implement Sheet.deleteObject()
Co-authored-by: Elliot <key.draw@gmail.com>
This commit is contained in:
parent
10c2b69bf3
commit
151fcce298
2 changed files with 31 additions and 0 deletions
|
@ -73,6 +73,14 @@ export default class Sheet {
|
||||||
return this._objects.getState()[key]
|
return this._objects.getState()[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteObject(objectKey: ObjectAddressKey) {
|
||||||
|
this._objects.reduceState([], (state) => {
|
||||||
|
const newState = {...state}
|
||||||
|
delete newState[objectKey]
|
||||||
|
return newState
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
getSequence(): Sequence {
|
getSequence(): Sequence {
|
||||||
if (!this._sequence) {
|
if (!this._sequence) {
|
||||||
const lengthD = valueDerivation(
|
const lengthD = valueDerivation(
|
||||||
|
|
|
@ -72,6 +72,13 @@ export interface ISheet {
|
||||||
options?: {override?: boolean},
|
options?: {override?: boolean},
|
||||||
): ISheetObject<Props>
|
): ISheetObject<Props>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a previously created child object for the sheet
|
||||||
|
*
|
||||||
|
* @param key - Delete the child object created with this key
|
||||||
|
*/
|
||||||
|
deleteObject(key: string): void
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Sequence of this Sheet
|
* The Sequence of this Sheet
|
||||||
*/
|
*/
|
||||||
|
@ -164,6 +171,22 @@ export default class TheatreSheet implements ISheet {
|
||||||
get address(): SheetAddress {
|
get address(): SheetAddress {
|
||||||
return {...privateAPI(this).address}
|
return {...privateAPI(this).address}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteObject(key: string) {
|
||||||
|
const internal = privateAPI(this)
|
||||||
|
const sanitizedPath = validateAndSanitiseSlashedPathOrThrow(
|
||||||
|
key,
|
||||||
|
`sheet.deleteObject("${key}")`,
|
||||||
|
) as ObjectAddressKey
|
||||||
|
|
||||||
|
const obj = internal.getObject(sanitizedPath)
|
||||||
|
if (!obj) {
|
||||||
|
console.warn(`Object key "${sanitizedPath}" does not exist.`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
internal.deleteObject(sanitizedPath as ObjectAddressKey)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const validateSequenceNameOrThrow = (value: string) => {
|
const validateSequenceNameOrThrow = (value: string) => {
|
||||||
|
|
Loading…
Reference in a new issue