rawmodel / framework

Strongly-typed JavaScript object with support for validation and error handling.
https://rawmodel.github.io/framework/
MIT License
143 stars 16 forks source link

`prop.commit()` sets incorrect `initialValue` for falsy primitive values #53

Closed dyurkavets closed 5 years ago

dyurkavets commented 5 years ago
import assert from 'assert'
import { Model, prop } from '@rawmodel/core'

class Issue extends Model {
    @prop()
    closed!: boolean

    @prop()
    priority!: number
}

const issue = new Issue({ closed: false, priority: 0 })

issue.commit()

// AssertionError [ERR_ASSERTION]: true == false
assert.equal(
    issue.isChanged(),
    false
)

// AssertionError [ERR_ASSERTION]: { closed: false, priority: 0 } deepEqual {}
assert.deepEqual(
    issue.filter((ref) => ref.prop.isChanged()),
    {}
)

https://github.com/rawmodel/framework/blob/master/packages/rawmodel-core/src/core/props.ts#L358

xpepermint commented 5 years ago

Thanks! I'll fix this asap.

xpepermint commented 5 years ago

https://github.com/rawmodel/framework/pull/54