updating

Usage

class User extends Model {
  static entity = 'users'
  static fields () {
    return {
      userId: this.attr(null),
      published: this.attr(false)
    }
  }
  static updating (model, record) {
      // change values before saving
    model.published = true
    if (model.userId === 2) {
        // prevent model with userId 2 being saved in the store
        return false
    }
    // check original data
    console.log(record)
  }
}

Typescript Declarations

export interface BeforeHook<M extends Model = Model> {
  (model: M, record?: Element): void | boolean
}
const updating: BeforeHook = () => {}