Options
All
  • Public
  • Public/Protected
  • All
Menu

Generic reactive graph. Consists from Identifiers, depending on each other. This is a low-level representation of the ChronoGraph dataset, it is not "aware" of the entity/relation framework and operates as "just graph".

For higher-level (and more convenient) representation, please refer to Replica.

An example of usage:

const graph      = ChronoGraph.new({ historyLimit : 10 })

const var1       = graph.variable(1)
const var2       = graph.variable(2)
const iden1      = graph.identifier((Y) => Y(var1) + Y(var2))

graph.read(iden1) // 3

graph.commit()

graph.write(var1, 2)

graph.read(iden1) // 4

graph.reject()

graph.read(var1) // 1
graph.read(iden1) // 3

Hierarchy

Index

Properties

autoCommit

autoCommit: boolean = false

If this option is enabled with true value, all data modification calls (write, addIdentifier, removeIdentifier) will trigger a delayed commit call (or commitAsync, depending from the autoCommitMode option).

autoCommitMode

autoCommitMode: "sync" | "async" = "sync"

Indicates the default commit mode, which is used in autoCommit.

historyLimit

historyLimit: number = 0

Integer value, indicating how many transactions to keep in memory, to be available for undo call. Default value is 0 - previous transaction is cleared immediately.

Increase this config to opt-in for the undo/redo functionality.

Methods

addIdentifier

  • addIdentifier<T>(identifier: T, proposedValue?: any, ...args: any[]): T
  • Adds an identifier to this graph. Optionally writes the proposedValue to it afterwards.

    Type parameters

    Parameters

    • identifier: T
    • Optional proposedValue: any
    • Rest ...args: any[]

    Returns T

branch

  • branch(config?: Partial<this>): this
  • Creates a new branch of this graph. Only committed data will be "visible" in the new branch.

    const graph2 = ChronoGraph.new()
    
    const variable13 : Variable<number> = graph2.variable(5)
    
    const branch2 = graph2.branch()
    
    branch2.write(variable13, 10)
    
    const value13_1 = graph2.read(variable13)  // 5
    const value13_2 = branch2.read(variable13) // 10

    When using the branching feature in Replica, you need to reference the field values by yielding their corresponding identifiers. This is because ChronoGraph need to know in context of which branch the calculation happens and this information is encoded in the outer context. This may improve in the future.

    class Author extends Entity.mix(Base) {
        @calculate('fullName')
        calculateFullName (Y) : string {
            return Y(this.$.firstName) + ' ' + Y(this.$.lastName)
        }
    
        @calculate('fullName')
        * calculateFullName (Y) : CalculationIterator<string> {
            return (yield this.$.firstName) + ' ' + (yield this.$.lastName)
        }
    }

    Parameters

    • Optional config: Partial<this>

      Configuration object for the new graph instance.

    Returns this

commit

  • Synchronously commit the state of the graph. All potentially changed strict identifiers will be calculated during this call. If any of such identifiers will be async, an exception will be thrown.

    This call marks a "stable" state of the graph and a transaction border. Using the undo call one can revert to the previous state.

    See also reject.

    Parameters

    Returns CommitResult

commitAsync

  • Asynchronously commit the state of the replica. All potentially changed strict identifiers (see Identifier.lazy) will be calculated during this call.

    This call marks a "stable" state of the graph and a transaction border. Using the undo call one can revert to the previous state.

    See also reject.

    Parameters

    Returns Promise<CommitResult>

get

  • get<T>(identifier: Identifier<T>): T | Promise<T>

hasIdentifier

hasPendingAutoCommit

  • hasPendingAutoCommit(): boolean
  • Returns boolean, indicating whether the auto-commit is pending.

    Returns boolean

identifier

  • identifier<ContextT, ValueT>(calculation: CalculationFunction<ContextT, ValueT, any, [CalculationContext<any>, any]>, context?: any): Identifier<ValueT, ContextT>
  • Creates an identifier based on the given calculation function and adds it to this graph. Depending form the type of the function (sync/generator) either CalculatedValueGen or CalculatedValueSync will be created.

    To have full control on the identifier creation, instantiate it yourself and add to graph using the ChronoGraph.addIdentifier call.

    Type parameters

    Parameters

    • calculation: CalculationFunction<ContextT, ValueT, any, [CalculationContext<any>, any]>

      The calculation function of the identifier.

    • Optional context: any

      The context property of the newly created identifier

    Returns Identifier<ValueT, ContextT>

identifierNamed

  • identifierNamed<ContextT, ValueT>(name: any, calculation: CalculationFunction<ContextT, ValueT, any, [CalculationContext<any>, any]>, context?: any): Identifier<ValueT, ContextT>

initialize

  • initialize<T>(props?: Partial<T>): void
  • This method applies its 1st argument (if any) to the current instance using Object.assign().

    Supposed to be overridden in the subclasses to customize the instance creation process.

    Type parameters

    Parameters

    • Optional props: Partial<T>

    Returns void

read

  • Synchronously read the value of the given identifier from the graph.

    Synchronous read can not calculate asynchronous identifiers and will throw exception

    Type parameters

    • T

    Parameters

    Returns T

readAsync

  • readAsync<T>(identifier: Identifier<T>): Promise<T>
  • Asynchronously read the value of the given identifier from the graph.

    Asynchronous read can calculate both synchronous and asynchronous identifiers

    Type parameters

    • T

    Parameters

    Returns Promise<T>

redo

  • redo(): boolean
  • Advance the replica to the state of next transaction (marked with the commit call). Only meaningful if a undo call has been made earlier.

    To enable this feature, you need to opt-in using the historyLimit configuration property.

    Returns boolean, indicating whether the state transition actually happened.

    Returns boolean

reject

  • reject<Reason>(reason?: Reason): void
  • Rejects the current changes in the graph and revert it to the state of the previous commit.

    See also RejectEffect.

    Type parameters

    • Reason

    Parameters

    • Optional reason: Reason

      Any value, describing why reject has happened

    Returns void

removeIdentifier

undo

  • undo(): boolean
  • Revert the replica to the state of previous transaction (marked with the commit call).

    To enable this feature, you need to opt-in using the historyLimit configuration property.

    Returns boolean, indicating whether the state transition actually happened.

    Returns boolean

variable

  • Creates a variable identifier with the given initial value and adds it to graph.

    Type parameters

    • T

    Parameters

    • value: T

      The initial value. The undefined value will be converted to null

    Returns Variable<T>

variableNamed

  • variableNamed<T>(name: any, value: T): Variable<T>
  • Creates a named variable identifier with the given initial value and adds it to graph.

    Type parameters

    • T

    Parameters

    • name: any

      The Variable.name property of the newly created variable

    • value: T

      The initial value. The undefined value will be converted to null

    Returns Variable<T>

write

  • write<T>(identifier: Identifier<T>, proposedValue: T, ...args: any[]): void
  • Writes a value to the given identifier.

    Type parameters

    • T

    Parameters

    • identifier: Identifier<T>
    • proposedValue: T
    • Rest ...args: any[]

    Returns void

Static new

  • new<T>(this: T, props?: Partial<InstanceType<T>>): InstanceType<T>
  • This is a type-safe static constructor method, accepting a single argument, with the object, corresponding to the class properties. It will generate a compilation error, if unknown property is provided.

    For example:

    class MyClass extends Base {
        prop     : string
    }
    
    const instance : MyClass = MyClass.new({ prop : 'prop', wrong : 11 })

    will produce:

    TS2345: Argument of type '{ prop: string; wrong: number; }' is not assignable to parameter of type 'Partial<MyClass>'.
    Object literal may only specify known properties, and 'wrong' does not exist in type 'Partial<MyClass>'

    The only thing this constructor does is create an instance and call the initialize method on it, forwarding the first argument. The customization of instance is supposed to be performed in that method.

    Type parameters

    Parameters

    • this: T
    • Optional props: Partial<InstanceType<T>>

    Returns InstanceType<T>

Generated using TypeDoc