Sanitize sequence's length
and subUnitsPerUnit
Possibly fixes P-173
This commit is contained in:
parent
ac9345ddbd
commit
8f1d26536b
1 changed files with 11 additions and 2 deletions
|
@ -9,6 +9,7 @@ import type SheetTemplate from './SheetTemplate'
|
||||||
import type {ObjectAddressKey, SheetInstanceId} from '@theatre/shared/utils/ids'
|
import type {ObjectAddressKey, SheetInstanceId} from '@theatre/shared/utils/ids'
|
||||||
import type {StrictRecord} from '@theatre/shared/utils/types'
|
import type {StrictRecord} from '@theatre/shared/utils/types'
|
||||||
import type {ILogger} from '@theatre/shared/logger'
|
import type {ILogger} from '@theatre/shared/logger'
|
||||||
|
import {isInteger} from 'lodash-es'
|
||||||
|
|
||||||
type SheetObjectMap = StrictRecord<ObjectAddressKey, SheetObject>
|
type SheetObjectMap = StrictRecord<ObjectAddressKey, SheetObject>
|
||||||
|
|
||||||
|
@ -77,12 +78,12 @@ export default class Sheet {
|
||||||
const lengthD = valueDerivation(
|
const lengthD = valueDerivation(
|
||||||
this.project.pointers.historic.sheetsById[this.address.sheetId].sequence
|
this.project.pointers.historic.sheetsById[this.address.sheetId].sequence
|
||||||
.length,
|
.length,
|
||||||
).map((s) => (typeof s === 'number' ? s : 10))
|
).map(sanitizeSequenceLength)
|
||||||
|
|
||||||
const subUnitsPerUnitD = valueDerivation(
|
const subUnitsPerUnitD = valueDerivation(
|
||||||
this.project.pointers.historic.sheetsById[this.address.sheetId].sequence
|
this.project.pointers.historic.sheetsById[this.address.sheetId].sequence
|
||||||
.subUnitsPerUnit,
|
.subUnitsPerUnit,
|
||||||
).map((s) => (typeof s === 'number' ? s : 30))
|
).map(sanitizeSequenceSubUnitsPerUnit)
|
||||||
|
|
||||||
this._sequence = new Sequence(
|
this._sequence = new Sequence(
|
||||||
this.template.project,
|
this.template.project,
|
||||||
|
@ -94,3 +95,11 @@ export default class Sheet {
|
||||||
return this._sequence
|
return this._sequence
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sanitizeSequenceLength = (len: number | undefined): number =>
|
||||||
|
typeof len === 'number' && isFinite(len) && len > 0 ? len : 10
|
||||||
|
|
||||||
|
const sanitizeSequenceSubUnitsPerUnit = (subs: number | undefined): number =>
|
||||||
|
typeof subs === 'number' && isInteger(subs) && subs >= 1 && subs <= 1000
|
||||||
|
? subs
|
||||||
|
: 30
|
||||||
|
|
Loading…
Reference in a new issue