-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUGFIX release beta canary] Fix Model lifecycle event deprecations #6395
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ module.exports = { | |
heimdall: true, | ||
Map: false, | ||
WeakMap: true, | ||
Set: true, | ||
}, | ||
env: { | ||
browser: true, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,24 +58,6 @@ interface BelongsToMetaWrapper { | |
modelName: string; | ||
} | ||
|
||
let INSTANCE_DEPRECATIONS; | ||
let lookupDeprecations; | ||
|
||
if (DEBUG) { | ||
INSTANCE_DEPRECATIONS = new WeakMap(); | ||
|
||
lookupDeprecations = function lookupInstanceDrecations(instance) { | ||
let deprecations = INSTANCE_DEPRECATIONS.get(instance); | ||
|
||
if (!deprecations) { | ||
deprecations = {}; | ||
INSTANCE_DEPRECATIONS.set(instance, deprecations); | ||
} | ||
|
||
return deprecations; | ||
}; | ||
} | ||
|
||
/* | ||
The TransitionChainMap caches the `state.enters`, `state.setups`, and final state reached | ||
when transitioning from one state to another, so that future transitions can replay the | ||
|
@@ -430,31 +412,6 @@ export default class InternalModel { | |
|
||
this._record = store._modelFactoryFor(this.modelName).create(createOptions); | ||
setRecordIdentifier(this._record, this.identifier); | ||
if (DEBUG) { | ||
let klass = this._record.constructor; | ||
let deprecations = lookupDeprecations(klass); | ||
[ | ||
'becameError', | ||
'becameInvalid', | ||
'didCreate', | ||
'didDelete', | ||
'didLoad', | ||
'didUpdate', | ||
'ready', | ||
'rolledBack', | ||
].forEach(methodName => { | ||
if (this instanceof Model && typeof this._record[methodName] === 'function') { | ||
deprecate( | ||
`Attempted to define ${methodName} on ${this._record.modelName}#${this._record.id}`, | ||
deprecations[methodName], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This never evaluated to |
||
{ | ||
id: 'ember-data:record-lifecycle-event-methods', | ||
until: '4.0', | ||
} | ||
); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
this._triggerDeferredTriggers(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1363,13 +1363,34 @@ if (DEBUG) { | |
return isBasicDesc(instanceDesc) && lookupDescriptor(obj.constructor, keyName) === null; | ||
}; | ||
|
||
const INSTANCE_DEPRECATIONS = new WeakMap(); | ||
const DEPRECATED_LIFECYCLE_EVENT_METHODS = [ | ||
'becameError', | ||
'becameInvalid', | ||
'didCreate', | ||
'didDelete', | ||
'didLoad', | ||
'didUpdate', | ||
'ready', | ||
'rolledBack', | ||
]; | ||
|
||
let lookupDeprecations = function lookupInstanceDeprecations(instance) { | ||
let deprecations = INSTANCE_DEPRECATIONS.get(instance); | ||
|
||
if (!deprecations) { | ||
deprecations = new Set(); | ||
INSTANCE_DEPRECATIONS.set(instance, deprecations); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if there is a way to avoid creating these data structures in memory if a user doesn't define any of these at all. Perhaps a majority don't? What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I definitely agree that the majority a model classes won't be defining any of these methods. I'm not sure if there is a way to avoid creating these but I'm not sure it matters much since this code will only run in development. It's not clear from this diff but this is all wrapped inside of an |
||
} | ||
|
||
return deprecations; | ||
}; | ||
|
||
Model.reopen({ | ||
init() { | ||
this._super(...arguments); | ||
|
||
if (DEBUG) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already wrapped an in |
||
this._getDeprecatedEventedInfo = () => `${this._internalModel.modelName}#${this.id}`; | ||
} | ||
this._getDeprecatedEventedInfo = () => `${this._internalModel.modelName}#${this.id}`; | ||
|
||
if (!isDefaultEmptyDescriptor(this, '_internalModel') || !(this._internalModel instanceof InternalModel)) { | ||
throw new Error( | ||
|
@@ -1393,6 +1414,24 @@ if (DEBUG) { | |
`You may not set 'id' as an attribute on your model. Please remove any lines that look like: \`id: DS.attr('<type>')\` from ${this.constructor.toString()}` | ||
); | ||
} | ||
|
||
let lifecycleDeprecations = lookupDeprecations(this.constructor); | ||
|
||
DEPRECATED_LIFECYCLE_EVENT_METHODS.forEach(methodName => { | ||
if (typeof this[methodName] === 'function' && !lifecycleDeprecations.has(methodName)) { | ||
deprecate( | ||
`You defined a \`${methodName}\` method for ${this.constructor.toString()} but lifecycle events for models have been deprecated.`, | ||
false, | ||
{ | ||
id: 'ember-data:record-lifecycle-event-methods', | ||
until: '4.0', | ||
url: 'https://deprecations.emberjs.com/ember-data/v3.x#toc_record-lifecycle-event-methods', | ||
} | ||
); | ||
|
||
lifecycleDeprecations.add(methodName); | ||
} | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
}, | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this
here was always an instance ofInternalModel
so this conditional was alwaysfalse