Skip to content

Migrating from 3.x to 4.0 ​

Version 4.0 closes public surfaces that allowed bypassing model invariants, and fixes a number of bugs. There are four breaking changes.

1. model.emitter removed → on / once ​

ts
// before
model.emitter.on(EventType.afterSetValue, cb)
model.emitter.once(EventType.afterSetValue, cb)

// after
model.on(EventType.afterSetValue, cb)      // on an instance
model.once(EventType.afterSetValue, cb)
Model.on(EventType.afterSetValue, cb)      // NEW: on the class, for every instance (and subclass)

emit() is no longer reachable from outside - a lifecycle event can't be forged. on/once still return an unsubscribe function.

2. startTracking() removed ​

The isTouched() snapshot is now only taken at creation: Model.create(data, { tracked: true }). Resetting the baseline after a save means recreating the model:

ts
// before
await api.save(form.toJSON())
form.startTracking()

// after
form = Form.create(await api.save(form.toJSON()), { tracked: true })

A model built via new Model(data) can't be tracked (isTouched() returns undefined).

3. create() throws a TypeError for an array ​

Model.create([...]) used to silently return an empty model. Now it throws with a hint; use Model.createFromCollection([...]) for lists.

4. createFromCollection skips only null / undefined ​

Any falsy value (0, '', false) used to be dropped. Now only null/undefined are.

Behavior changes (non-breaking) ​

WhatBeforeAfter
Subscriptions on a parent classdidn't fire for subclassesfire
created / touched payloadnone{ target }
touched during create()emitted for the initial fillnot emitted
touched and a rejected writeemitted before the checksemitted after a successful write; bubbles up from nested models
A value: [] / {} defaultone object shared by every instancea copy per instance
once in @ActiveFieldcould miss if the first event was for another fieldfires on the first event of its own field
@ActiveFactory(undefined)silently did nothingReferenceError at class definition
An exception in a listeneraborted the remaining listenersall listeners run, then the first error is thrown
toJSON() for Date/Set/Map{}ISO string / array / object
clone()a plain object without Proxy, lost hiddena full model, hidden kept, baseline carried over
makeFreeze()confusing error about Symbol(@touched)a clear TypeError
'hidden' in modeltruefalse
createFromCollectiontyped ActiveModel[]InstanceType<T>[]
CallableModelextends Function (needs unsafe-eval under CSP)a plain function, CSP-safe
ESM buildAsyncLocalStorage silently disablednot used at all