Skip to content

Obj

Base object.

  1. have unique id
  2. have parent and children
  3. can be serialized (store and copy-paste)
  4. can be traversed

Extended by

Constructors

new Obj()

new Obj(): Obj

Returns

Obj

Source

packages/core/src/core/obj.ts:16

Properties

children

children: Obj[]

Source

packages/core/src/core/obj.ts:14


id

id: string

Source

packages/core/src/core/obj.ts:11


parent

parent: null | Obj

Source

packages/core/src/core/obj.ts:13


type

type: string

Source

packages/core/src/core/obj.ts:12

Methods

find()

find(pred): null | Obj

Find an shape in breath-first order

Parameters

pred

Returns

null | Obj

Source

packages/core/src/core/obj.ts:363


findDepthFirst()

findDepthFirst(pred): null | Obj

Find an shape in depth-first order

Parameters

pred

Returns

null | Obj

Source

packages/core/src/core/obj.ts:376


findParent()

findParent(pred): null | Obj

Find a shape along with the parent-chain

Parameters

pred

Returns

null | Obj

Source

packages/core/src/core/obj.ts:389


fromJSON()

fromJSON(json): void

Parameters

json: any

Returns

void

Source

packages/core/src/core/obj.ts:294


isDescendant()

isDescendant(obj): boolean

Test whether the given shape is a descendant

Parameters

obj: Obj

Returns

boolean

Source

packages/core/src/core/obj.ts:399


readAny()

readAny(json, field, defaultValue): any

Read an any value from the JSON object, return defaultValue if the field is undefined.

Parameters

json: any

field: string

defaultValue: any

Returns

any

Source

packages/core/src/core/obj.ts:54


readArrayAny()

readArrayAny(json, field, defaultValue): any[]

Read an array of any value from the JSON object, return defaultValue if the field is not an array.

Parameters

json: any

field: string

defaultValue: any[]

Returns

any[]

Source

packages/core/src/core/obj.ts:65


readArrayBoolean()

readArrayBoolean(json, field, defaultValue, length?): boolean[]

Read an array of boolean from the JSON object, return defaultValue if the field is not an array of boolean.

Parameters

json: any

field: string

defaultValue: boolean[]

length?: number

Returns

boolean[]

Source

packages/core/src/core/obj.ts:148


readArrayNumber()

readArrayNumber(json, field, defaultValue, length?): number[]

Read a number field from the JSON object, return defaultValue if the field is not a number.

Parameters

json: any

field: string

defaultValue: number[]

length?: number

Returns

number[]

Source

packages/core/src/core/obj.ts:87


readArrayPoint()

readArrayPoint(json, field, defaultValue): [number, number][]

Read a, array of point value from the JSON object, return defaultValue if the field is not an array of point.

Parameters

json: any

field: string

defaultValue: [number, number][]

Returns

[number, number][]

Source

packages/core/src/core/obj.ts:256


readArrayString()

readArrayString(json, field, defaultValue): string[]

Read an array of string from the JSON object, return defaultValue if the field is not an array of string.

Parameters

json: any

field: string

defaultValue: string[]

Returns

string[]

Source

packages/core/src/core/obj.ts:123


readBoolean()

readBoolean(json, field, defaultValue): boolean

Read a boolean field from the JSON object, return defaultValue if the field is not a boolean.

Parameters

json: any

field: string

defaultValue: boolean

Returns

boolean

Source

packages/core/src/core/obj.ts:137


readColor()

readColor(json, field, defaultValue): string

Read a color field from the JSON object, return defaultValue if the field is not a string or not a valid color.

Parameters

json: any

field: string

defaultValue: string

Returns

string

Source

packages/core/src/core/obj.ts:170


readEnum()

readEnum(json, field, enumType, defaultValue): string

Read an enum value from the JSON object, return defaultValue if the field is not a valid enum value.

Parameters

json: any

field: string

enumType: any

defaultValue: string

Returns

string

Source

packages/core/src/core/obj.ts:185


readNumber()

readNumber(json, field, defaultValue): number

Read a number field from the JSON object, return defaultValue if the field is not a number.

Parameters

json: any

field: string

defaultValue: number

Returns

number

Source

packages/core/src/core/obj.ts:76


readPoint()

readPoint(json, field, defaultValue): [number, number]

Read a point value from the JSON object, return defaultValue if the field is not a point.

Parameters

json: any

field: string

defaultValue: [number, number]

Returns

[number, number]

Source

packages/core/src/core/obj.ts:213


readPointOrNull()

readPointOrNull(json, field, defaultValue): null | [number, number]

Read a point or null value from the JSON object, return defaultValue if the field is not a point or null.

Parameters

json: any

field: string

defaultValue: null | [number, number]

Returns

null | [number, number]

Source

packages/core/src/core/obj.ts:233


readRef()

readRef(json, field): null | string

Read a reference to object from the JSON object, return defaultValue if the field is not string (obj’s id) or null.

Parameters

json: any

field: string

Returns

null | string

Source

packages/core/src/core/obj.ts:202


readString()

readString(json, field, defaultValue): string

Read a string field from the JSON object, return defaultValue if the field is not a string.

Parameters

json: any

field: string

defaultValue: string

Returns

string

Source

packages/core/src/core/obj.ts:112


resolveRefs()

resolveRefs(idMap, nullIfNotFound): void

Resolve references

Parameters

idMap: Record<string, Obj>

id to object map

nullIfNotFound: boolean= false

assign null if not found

Returns

void

Source

packages/core/src/core/obj.ts:304


setJson()

setJson(json, field, value, defaultValue, enforce): void

Set a field in the JSON object only if the value is defined and not equal to the default value.

Parameters

json: any

The JSON object to set the field in.

field: string

The field name to set.

value: any

The value to set.

defaultValue: any

The default value to compare against.

enforce: boolean= false

If true, the field will be set even if it is equal to the default value.

Returns

void

Source

packages/core/src/core/obj.ts:31


toJSON()

toJSON(recursive, keepRefs, enforce): any

Parameters

recursive: boolean= false

keepRefs: boolean= false

enforce: boolean= false

Returns

any

Source

packages/core/src/core/obj.ts:276


traverse()

traverse(fun, parent): void

Traverse all objects in breath-first order

Parameters

fun

parent: null | Obj= null

Returns

void

Source

packages/core/src/core/obj.ts:317


traverseDepthFirst()

traverseDepthFirst(fun, parent): void

Traverse all shapes in depth-first order

Parameters

fun

parent: null | Obj= null

Returns

void

Source

packages/core/src/core/obj.ts:331


traverseDepthFirstSequence()

traverseDepthFirstSequence(): Obj[]

Returns an array of shapes in order of traverse sequence.

Returns

Obj[]

Source

packages/core/src/core/obj.ts:354


traverseSequence()

traverseSequence(): Obj[]

Returns an array of shapes in order of traverse sequence.

Returns

Obj[]

Source

packages/core/src/core/obj.ts:345