lib/immutable-core-task/sync.js
/**
 * @function sync
 *
 * sync task record and set taskId
 */
@function sync
sync task record and set taskId
@function sync sync task record and set taskId
async function sync () {
    var model = this.taskModel()
    var dataId = stableId(this)
    var task = await model.query({
        one: true,
        where: { name: this.name }
    })
    if (defined(task)) {
        var taskDataId = stableId(task.data)
        if (taskDataId === dataId) {
            this.taskId = task.id
        }
        else {
            task = await task.updateMeta({
                data: this.toJSON(),
                merge: false,
            })
            this.taskId = task.id
        }
    }
    else {
        task = await model.create(this.toJSON())
        this.taskId = task.id
    }
    this.global().tasksById[this.taskId] = this
}
async function sync ( ) { var model = this . taskModel ( ) var dataId = stableId ( this ) var task = await model . query ( { one : true , where : { name : this . name } } ) if ( defined ( task ) ) { var taskDataId = stableId ( task . data ) if ( taskDataId === dataId ) { this . taskId = task . id } else { task = await task . updateMeta ( { data : this . toJSON ( ) , merge : false , } ) this . taskId = task . id } } else { task = await model . create ( this . toJSON ( ) ) this . taskId = task . id } this . global ( ) . tasksById [ this . taskId ] = this }
@function sync
 sync task record and set taskId
@function sync sync task record and set taskId
// get model - throws error if not set // calculate id for instance data // load most recent task record for name if any // if task is found then check if it is same // get id for task data // if definition has not changed then use this record // otherwise update record with current data // set task with current data // set task id from updated task // create new task // set task id from newly created task // add to global register