Conveyor Models

The ConveyorModel is the hub for all conveyor data.

ConveyorModel

Methods

  • prototype.addInterface
  • prototype.setFields
  • prototype.setComputed
  • prototype.setValidators
Conveyor.registerModel('Event')
    .addInterface('api', new ConveyorHttpInterface({endpoint:'/api/v1/events'}))
    .setFields({
        id: Number,
        start_date: {type:Date,nullable:true},
        end_date: Date,
        user_id: Number
    })
    .setComputed({
        user: {
            get: function() {
                return Conveyor.getModel('User',this.get('user_id'));
            },
            set: function(input) {
                this.set('user_id', input.id);
            }
        }
    )
    // validators are run post-transform and cannot manipulate value
    .setValidators({
        'checkDate':function(state,oldState){
            if(state.start_date > state.end_date) {
                throw this.start_date.exception('Start date must be before end date.');
            }
        }
    });

ConveyorModelState

The ConveyorModelState object tracks a collection of ConveyorModelValue objects to get the current state of a ConveyorModel.

  • state.changed
  • state.undo([fields]) - duplicates the previous state and pushes it
  • state.redo() - un-undos the last undo call
  • state.diff([state]) - returns the difference between the last (or specified state)

ConveyorModelValue

A value object is generated for each model value. When a change is applied, it is duplicated and attached to the new state.

Methods

  • exception(message) - Returns a new ConveyorModelValueException for the specific field.
  • get() - Gets the value of the field after transformers.
  • set(value) - Runs the new value through transformers and then validators.

Properties

  • raw - Get the raw stored value (no transformers)
  • changed - Boolean indication of whether it has changed from the original value.
  • saved - Indication of whether the value has been saved or not.
  • errors - Array of errors generated from validators.

results matching ""

    No results matching ""