mirror of
https://github.com/flarum/core.git
synced 2025-07-16 14:26:25 +02:00
fix: replace throw with debug warning to fix breaking change (#3206)
* fix: replace throw with debug warning to fix breaking change * Add link back to PR in warning * fix: add missing `return null` for `!allowUnregistered` code path * Clean up message -- move more info to PR comment * Add setTimeout to delay call debug warning call until after `app.forum` is defined * Add backticks around data type
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
import app from '../common/app';
|
import app from '../common/app';
|
||||||
import { FlarumRequestOptions } from './Application';
|
import { FlarumRequestOptions } from './Application';
|
||||||
|
import fireDebugWarning from './helpers/fireDebugWarning';
|
||||||
import Model, { ModelData, SavedModelData } from './Model';
|
import Model, { ModelData, SavedModelData } from './Model';
|
||||||
|
|
||||||
export interface MetaInformation {
|
export interface MetaInformation {
|
||||||
@ -120,11 +121,17 @@ export default class Store {
|
|||||||
pushObject<M extends Model>(data: SavedModelData, allowUnregistered: false): M;
|
pushObject<M extends Model>(data: SavedModelData, allowUnregistered: false): M;
|
||||||
pushObject<M extends Model>(data: SavedModelData, allowUnregistered = true): M | null {
|
pushObject<M extends Model>(data: SavedModelData, allowUnregistered = true): M | null {
|
||||||
if (!this.models[data.type]) {
|
if (!this.models[data.type]) {
|
||||||
if (allowUnregistered) {
|
if (!allowUnregistered) {
|
||||||
return null;
|
setTimeout(() =>
|
||||||
|
fireDebugWarning(
|
||||||
|
`[Flarum 2.0 Deprecation] Cannot push object of type \`${data.type}\`, as that type has not yet been registered in the store. This will throw an error in Flarum 2.0 and later.
|
||||||
|
|
||||||
|
For more information, see https://github.com/flarum/core/pull/3206.`
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(`Cannot push object of type ${data.type}, as that type has not yet been registered in the store.`);
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const type = (this.data[data.type] = this.data[data.type] || {});
|
const type = (this.data[data.type] = this.data[data.type] || {});
|
||||||
|
Reference in New Issue
Block a user