self-assert / IntegerDraftAssistant
Class: IntegerDraftAssistant<ContainerModel>
Provides an assistant for the completion of an integer field, represented by a string.
Extends
SectionDraftAssistant
<number
,ContainerModel
, [string
]>
Type Parameters
Type Parameter | Default type |
---|---|
ContainerModel | any |
Constructors
Constructor
new IntegerDraftAssistant<
ContainerModel
>(assistants
,creationClosure
,modelFromContainer
,assertionIds
):IntegerDraftAssistant
<ContainerModel
>
Parameters
Parameter | Type |
---|---|
assistants | [DraftAssistant <string , number >] |
creationClosure | CreationClosure <number , [string ]> |
modelFromContainer | ModelFromContainer <number , ContainerModel > |
assertionIds | string [] |
Returns
IntegerDraftAssistant
<ContainerModel
>
Inherited from
SectionDraftAssistant
.constructor
Error handling
handleError()
handleError(
possibleCreateModelError
):void
Parameters
Parameter | Type |
---|---|
possibleCreateModelError | unknown |
Returns
void
Inherited from
SectionDraftAssistant
.handleError
routeBrokenRulesOf()
routeBrokenRulesOf(
aRulesBrokenError
):void
Parameters
Parameter | Type |
---|---|
aRulesBrokenError | RulesBroken |
Returns
void
Inherited from
SectionDraftAssistant
.routeBrokenRulesOf
routeBrokenRule()
routeBrokenRule(
brokenRule
):void
Parameters
Parameter | Type |
---|---|
brokenRule | LabeledRule |
Returns
void
Inherited from
SectionDraftAssistant
.routeBrokenRule
Model creation
isInvalidModel()
static
isInvalidModel(potentialModel
):boolean
Parameters
Parameter | Type |
---|---|
potentialModel | unknown |
Returns
boolean
Inherited from
SectionDraftAssistant
.isInvalidModel
createModel()
createModel():
number
Attempts to create a model. It fails if any of the assertions fail.
Returns
number
See
Throws
RulesBroken if the model is invalid
Inherited from
SectionDraftAssistant
.createModel
setModel()
setModel(
newModel
):void
Parameters
Parameter | Type |
---|---|
newModel | number |
Returns
void
Inherited from
SectionDraftAssistant
.setModel
resetModel()
resetModel():
void
Resets the model to its initial value.
Returns
void
Inherited from
SectionDraftAssistant
.resetModel
withCreatedModelDo()
withCreatedModelDo<
ReturnType
>(validModelClosure
,invalidModelClosure
):ReturnType
Executes a closure depending on whether the model is valid or not after creating it.
Type Parameters
Type Parameter | Description |
---|---|
ReturnType | The type of the value returned by the closures. |
Parameters
Parameter | Type | Description |
---|---|---|
validModelClosure | (model ) => ReturnType | A closure that will be called with the created model if it's valid. |
invalidModelClosure | () => ReturnType | A closure that will be called if the model is invalid. |
Returns
ReturnType
The return value of the closure that was called.
Inherited from
SectionDraftAssistant
.withCreatedModelDo
getModel()
getModel():
number
Returns
number
Inherited from
SectionDraftAssistant
.getModel
setModelFrom()
setModelFrom(
containerModel
):void
Sets the model from its container.
Parameters
Parameter | Type |
---|---|
containerModel | ContainerModel |
Returns
void
Inherited from
SectionDraftAssistant
.setModelFrom
Rules
addBrokenRule()
addBrokenRule(
aBrokenRuleLabel
):void
Adds a rule to the list of broken rules.
Parameters
Parameter | Type |
---|---|
aBrokenRuleLabel | LabeledRule |
Returns
void
Inherited from
SectionDraftAssistant
.addBrokenRule
addBrokenRules()
addBrokenRules(
brokenRules
):void
Adds a list of rules to the list of broken rules.
Parameters
Parameter | Type |
---|---|
brokenRules | LabeledRule [] |
Returns
void
Inherited from
SectionDraftAssistant
.addBrokenRules
hasBrokenRules()
hasBrokenRules():
boolean
Returns
boolean
true
if the list of broken rules is not empty
Inherited from
SectionDraftAssistant
.hasBrokenRules
doesNotHaveBrokenRules()
doesNotHaveBrokenRules():
boolean
Opposite of hasBrokenRules.
Returns
boolean
Inherited from
SectionDraftAssistant
.doesNotHaveBrokenRules
brokenRulesDescriptions()
brokenRulesDescriptions():
string
[]
Returns
string
[]
The descriptions of the broken rules
Inherited from
SectionDraftAssistant
.brokenRulesDescriptions
handles()
handles(
aRule
):boolean
Parameters
Parameter | Type |
---|---|
aRule | LabeledRule |
Returns
boolean
true
if this assistant handles the given Assertion
.
Inherited from
addLabelId()
addLabelId(
aLabelId
):void
Adds an assertion id to the list of handled assertions.
Parameters
Parameter | Type |
---|---|
aLabelId | string |
Returns
void
Inherited from
SectionDraftAssistant
.addLabelId
hasBrokenRule()
hasBrokenRule(
aBrokenRuleLabel
):boolean
Parameters
Parameter | Type |
---|---|
aBrokenRuleLabel | LabeledRule |
Returns
boolean
Inherited from
SectionDraftAssistant
.hasBrokenRule
hasOnlyOneRuleBrokenIdentifiedAs()
hasOnlyOneRuleBrokenIdentifiedAs(
assertionId
):boolean
Parameters
Parameter | Type |
---|---|
assertionId | string |
Returns
boolean
true
if this assistant has only one failed assertion that is identified as the given assertionId
.
Remarks
Used mostly for testing.
Inherited from
SectionDraftAssistant
.hasOnlyOneRuleBrokenIdentifiedAs
removeBrokenRules()
removeBrokenRules():
void
Returns
void
Inherited from
SectionDraftAssistant
.removeBrokenRules
Viewers
accept()
accept(
aViewer
):void
Adds a viewer to the list of observers.
Parameters
Parameter | Type |
---|---|
aViewer | DraftViewer <number > |
Returns
void
Inherited from
removeViewer()
removeViewer(
aViewer
):void
Removes a viewer from the list of observers.
Parameters
Parameter | Type |
---|---|
aViewer | DraftViewer <never > |
Returns
void
Inherited from
SectionDraftAssistant
.removeViewer
numberOfViewers()
numberOfViewers():
number
Returns
number
The number of viewers currently observing the assistant.
Inherited from
SectionDraftAssistant
.numberOfViewers
Others
defaultAssertionDescription
readonly
static
defaultAssertionDescription:"Invalid integer"
="Invalid integer"
for()
static
for<ContainerModel
>(assertionId
,modelFromContainer
):IntegerDraftAssistant
<ContainerModel
>
Type Parameters
Type Parameter |
---|
ContainerModel |
Parameters
Parameter | Type |
---|---|
assertionId | string |
modelFromContainer | ModelFromContainer <number , ContainerModel > |
Returns
IntegerDraftAssistant
<ContainerModel
>
forTopLevel()
static
forTopLevel(assertionId
):IntegerDraftAssistant
<unknown
>
Parameters
Parameter | Type |
---|---|
assertionId | string |
Returns
IntegerDraftAssistant
<unknown
>
createInteger()
static
createInteger(assertionId
,numberAsString
):number
Parameters
Parameter | Type |
---|---|
assertionId | string |
numberAsString | string |
Returns
number
createNumberAssistant()
static
createNumberAssistant():FieldDraftAssistant
<number
,string
>
Returns
FieldDraftAssistant
<number
, string
>
createAssertionFor()
static
createAssertionFor(assertionId
,numberAsString
):Assertion
<void
>
Parameters
Parameter | Type |
---|---|
assertionId | string |
numberAsString | string |
Returns
Assertion
<void
>
with()
static
with<Model
,ContainerModel
,ComposedModels
>(assistants
,creationClosure
,modelFromContainer
,assertionIds
):SectionDraftAssistant
<Model
,ContainerModel
,ComposedModels
>
Type Parameters
Type Parameter | Default type |
---|---|
Model | any |
ContainerModel | any |
ComposedModels extends unknown [] | any [] |
Parameters
Parameter | Type |
---|---|
assistants | AssistantsIn <ComposedModels , Model > |
creationClosure | CreationClosure <Model , ComposedModels > |
modelFromContainer | ModelFromContainer <Model , ContainerModel > |
assertionIds | string [] |
Returns
SectionDraftAssistant
<Model
, ContainerModel
, ComposedModels
>
Inherited from
topLevelContainerWith()
static
topLevelContainerWith<Model
,ComposedModels
>(assistants
,creationClosure
,assertionIds
):SectionDraftAssistant
<Model
,unknown
,ComposedModels
>
Type Parameters
Type Parameter | Default type |
---|---|
Model | any |
ComposedModels extends unknown [] | any [] |
Parameters
Parameter | Type | Default value |
---|---|---|
assistants | AssistantsIn <ComposedModels , Model > | undefined |
creationClosure | CreationClosure <Model , ComposedModels > | undefined |
assertionIds | string [] | [] |
Returns
SectionDraftAssistant
<Model
, unknown
, ComposedModels
>
Inherited from
SectionDraftAssistant
.topLevelContainerWith
topLevelModelFromContainer()
static
topLevelModelFromContainer<Model
>():ModelFromContainer
<Model
,unknown
>
Type Parameters
Type Parameter | Default type |
---|---|
Model | any |
Returns
ModelFromContainer
<Model
, unknown
>
A default model getter from a container for the top-level assistant. Since there is no container to get the model from, it throws an error.
Inherited from
SectionDraftAssistant
.topLevelModelFromContainer
innerAssistant()
innerAssistant():
DraftAssistant
<string
,number
>
Returns
DraftAssistant
<string
, number
>
setInnerModel()
setInnerModel(
newModel
):void
Parameters
Parameter | Type |
---|---|
newModel | string |
Returns
void
getInnerModel()
getInnerModel():
string
Returns
string