Skip to content

self-assert / SectionDraftAssistant

Class: SectionDraftAssistant<Model, ContainerModel, ComposedModels> ​

Assists in the creation of complex models by coordinating multiple inner DraftAssistant.

It uses a CreationClosure function to combine the models created by its assistants into a single composed model.

Extends ​

Extended by ​

Type Parameters ​

Type ParameterDefault typeDescription
Modelany-
ContainerModelany-
ComposedModels extends unknown[]any[]An array of types representing the types of the models created by the inner assistants, in the same order as the assistants array.

Constructors ​

Constructor ​

new SectionDraftAssistant<Model, ContainerModel, ComposedModels>(assistants, creationClosure, modelFromContainer, assertionIds): SectionDraftAssistant<Model, ContainerModel, ComposedModels>

Parameters ​

ParameterType
assistantsAssistantsIn<ComposedModels, Model>
creationClosureCreationClosure<Model, ComposedModels>
modelFromContainerModelFromContainer<Model, ContainerModel>
assertionIdsstring[]

Returns ​

SectionDraftAssistant<Model, ContainerModel, ComposedModels>

Overrides ​

DraftAssistant<Model, ContainerModel>.constructor

Error handling ​

handleError() ​

handleError(possibleCreateModelError): void

Parameters ​

ParameterType
possibleCreateModelErrorunknown

Returns ​

void


routeBrokenRulesOf() ​

routeBrokenRulesOf(aRulesBrokenError): void

Parameters ​

ParameterType
aRulesBrokenErrorRulesBroken

Returns ​

void


routeBrokenRule() ​

routeBrokenRule(brokenRule): void

Parameters ​

ParameterType
brokenRuleLabeledRule

Returns ​

void

Model creation ​

isInvalidModel() ​

static isInvalidModel(potentialModel): boolean

Parameters ​

ParameterType
potentialModelunknown

Returns ​

boolean

Inherited from ​

DraftAssistant.isInvalidModel


createModel() ​

createModel(): Model

Attempts to create a model. It fails if any of the assertions fail.

Returns ​

Model

See ​

withCreatedModelDo.

Throws ​

RulesBroken if the model is invalid

Overrides ​

DraftAssistant.createModel


setModel() ​

setModel(newModel): void

Parameters ​

ParameterType
newModelModel

Returns ​

void

Overrides ​

DraftAssistant.setModel


resetModel() ​

resetModel(): void

Resets the model to its initial value.

Returns ​

void

Overrides ​

DraftAssistant.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 ParameterDescription
ReturnTypeThe type of the value returned by the closures.

Parameters ​

ParameterTypeDescription
validModelClosure(model) => ReturnTypeA closure that will be called with the created model if it's valid.
invalidModelClosure() => ReturnTypeA closure that will be called if the model is invalid.

Returns ​

ReturnType

The return value of the closure that was called.

Inherited from ​

DraftAssistant.withCreatedModelDo


getModel() ​

getModel(): Model

Returns ​

Model

Inherited from ​

DraftAssistant.getModel


setModelFrom() ​

setModelFrom(containerModel): void

Sets the model from its container.

Parameters ​

ParameterType
containerModelContainerModel

Returns ​

void

Inherited from ​

DraftAssistant.setModelFrom

Rules ​

addBrokenRule() ​

addBrokenRule(aBrokenRuleLabel): void

Adds a rule to the list of broken rules.

Parameters ​

ParameterType
aBrokenRuleLabelLabeledRule

Returns ​

void

Inherited from ​

DraftAssistant.addBrokenRule


addBrokenRules() ​

addBrokenRules(brokenRules): void

Adds a list of rules to the list of broken rules.

Parameters ​

ParameterType
brokenRulesLabeledRule[]

Returns ​

void

Inherited from ​

DraftAssistant.addBrokenRules


hasBrokenRules() ​

hasBrokenRules(): boolean

Returns ​

boolean

true if the list of broken rules is not empty

Inherited from ​

DraftAssistant.hasBrokenRules


doesNotHaveBrokenRules() ​

doesNotHaveBrokenRules(): boolean

Opposite of hasBrokenRules.

Returns ​

boolean

Inherited from ​

DraftAssistant.doesNotHaveBrokenRules


brokenRulesDescriptions() ​

brokenRulesDescriptions(): string[]

Returns ​

string[]

The descriptions of the broken rules

Inherited from ​

DraftAssistant.brokenRulesDescriptions


handles() ​

handles(aRule): boolean

Parameters ​

ParameterType
aRuleLabeledRule

Returns ​

boolean

true if this assistant handles the given Assertion.

Inherited from ​

DraftAssistant.handles


addLabelId() ​

addLabelId(aLabelId): void

Adds an assertion id to the list of handled assertions.

Parameters ​

ParameterType
aLabelIdstring

Returns ​

void

Inherited from ​

DraftAssistant.addLabelId


hasBrokenRule() ​

hasBrokenRule(aBrokenRuleLabel): boolean

Parameters ​

ParameterType
aBrokenRuleLabelLabeledRule

Returns ​

boolean

Inherited from ​

DraftAssistant.hasBrokenRule


hasOnlyOneRuleBrokenIdentifiedAs() ​

hasOnlyOneRuleBrokenIdentifiedAs(assertionId): boolean

Parameters ​

ParameterType
assertionIdstring

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 ​

DraftAssistant.hasOnlyOneRuleBrokenIdentifiedAs


removeBrokenRules() ​

removeBrokenRules(): void

Returns ​

void

Inherited from ​

DraftAssistant.removeBrokenRules

Viewers ​

accept() ​

accept(aViewer): void

Adds a viewer to the list of observers.

Parameters ​

ParameterType
aViewerDraftViewer<Model>

Returns ​

void

Inherited from ​

DraftAssistant.accept


removeViewer() ​

removeViewer(aViewer): void

Removes a viewer from the list of observers.

Parameters ​

ParameterType
aViewerDraftViewer<never>

Returns ​

void

Inherited from ​

DraftAssistant.removeViewer


numberOfViewers() ​

numberOfViewers(): number

Returns ​

number

The number of viewers currently observing the assistant.

Inherited from ​

DraftAssistant.numberOfViewers

Others ​

with() ​

static with<Model, ContainerModel, ComposedModels>(assistants, creationClosure, modelFromContainer, assertionIds): SectionDraftAssistant<Model, ContainerModel, ComposedModels>

Type Parameters ​

Type ParameterDefault type
Modelany
ContainerModelany
ComposedModels extends unknown[]any[]

Parameters ​

ParameterType
assistantsAssistantsIn<ComposedModels, Model>
creationClosureCreationClosure<Model, ComposedModels>
modelFromContainerModelFromContainer<Model, ContainerModel>
assertionIdsstring[]

Returns ​

SectionDraftAssistant<Model, ContainerModel, ComposedModels>


topLevelContainerWith() ​

static topLevelContainerWith<Model, ComposedModels>(assistants, creationClosure, assertionIds): SectionDraftAssistant<Model, unknown, ComposedModels>

Type Parameters ​

Type ParameterDefault type
Modelany
ComposedModels extends unknown[]any[]

Parameters ​

ParameterTypeDefault value
assistantsAssistantsIn<ComposedModels, Model>undefined
creationClosureCreationClosure<Model, ComposedModels>undefined
assertionIdsstring[][]

Returns ​

SectionDraftAssistant<Model, unknown, ComposedModels>


topLevelModelFromContainer() ​

static topLevelModelFromContainer<Model>(): ModelFromContainer<Model, unknown>

Type Parameters ​

Type ParameterDefault type
Modelany

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 ​

DraftAssistant.topLevelModelFromContainer