mirror of
https://github.com/flarum/framework.git
synced 2025-02-23 04:26:23 +08:00
Add warnings to Mithril 2 BC layer (#2313)
This commit is contained in:
parent
82af307280
commit
c53509d7d0
@ -1,5 +1,8 @@
|
|||||||
import * as Mithril from 'mithril';
|
import * as Mithril from 'mithril';
|
||||||
|
|
||||||
|
let deprecatedPropsWarned = false;
|
||||||
|
let deprecatedInitPropsWarned = false;
|
||||||
|
|
||||||
export type ComponentAttrs = {
|
export type ComponentAttrs = {
|
||||||
className?: string;
|
className?: string;
|
||||||
|
|
||||||
@ -134,20 +137,15 @@ export default abstract class Component<T extends ComponentAttrs = any> implemen
|
|||||||
*/
|
*/
|
||||||
protected static initAttrs<T>(attrs: T): void {
|
protected static initAttrs<T>(attrs: T): void {
|
||||||
// Deprecated, part of Mithril 2 BC layer
|
// Deprecated, part of Mithril 2 BC layer
|
||||||
this.initProps(attrs);
|
if ('initProps' in this && !deprecatedInitPropsWarned) {
|
||||||
|
deprecatedInitPropsWarned = true;
|
||||||
|
console.warn('initProps is deprecated, please use initAttrs instead.');
|
||||||
|
(this as any).initProps(attrs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// BEGIN DEPRECATED MITHRIL 2 BC LAYER
|
// BEGIN DEPRECATED MITHRIL 2 BC LAYER
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize the component's attrs.
|
|
||||||
*
|
|
||||||
* This can be used to assign default values for missing, optional attrs.
|
|
||||||
*
|
|
||||||
* @deprecated, use initAttrs instead.
|
|
||||||
*/
|
|
||||||
protected static initProps<T>(attrs: T): void {}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The attributes passed into the component.
|
* The attributes passed into the component.
|
||||||
*
|
*
|
||||||
@ -156,9 +154,17 @@ export default abstract class Component<T extends ComponentAttrs = any> implemen
|
|||||||
* @deprecated, use attrs instead.
|
* @deprecated, use attrs instead.
|
||||||
*/
|
*/
|
||||||
get props() {
|
get props() {
|
||||||
|
if (!deprecatedPropsWarned) {
|
||||||
|
deprecatedPropsWarned = true;
|
||||||
|
console.warn('this.props is deprecated, please use this.attrs instead.');
|
||||||
|
}
|
||||||
return this.attrs;
|
return this.attrs;
|
||||||
}
|
}
|
||||||
set props(props) {
|
set props(props) {
|
||||||
|
if (!deprecatedPropsWarned) {
|
||||||
|
deprecatedPropsWarned = true;
|
||||||
|
console.warn('this.props is deprecated, please use this.attrs instead.');
|
||||||
|
}
|
||||||
this.attrs = props;
|
this.attrs = props;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,9 @@ import Stream from 'mithril/stream';
|
|||||||
import extract from './extract';
|
import extract from './extract';
|
||||||
import withAttr from './withAttr';
|
import withAttr from './withAttr';
|
||||||
|
|
||||||
|
let deprecatedMPropWarned = false;
|
||||||
|
let deprecatedMWithAttrWarned = false;
|
||||||
|
|
||||||
export default function patchMithril(global) {
|
export default function patchMithril(global) {
|
||||||
const defaultMithril = global.m;
|
const defaultMithril = global.m;
|
||||||
|
|
||||||
@ -70,9 +73,21 @@ export default function patchMithril(global) {
|
|||||||
modifiedMithril.route.Link = modifiedLink;
|
modifiedMithril.route.Link = modifiedLink;
|
||||||
|
|
||||||
// BEGIN DEPRECATED MITHRIL 2 BC LAYER
|
// BEGIN DEPRECATED MITHRIL 2 BC LAYER
|
||||||
modifiedMithril.prop = Stream;
|
modifiedMithril.prop = function (...args) {
|
||||||
|
if (!deprecatedMPropWarned) {
|
||||||
|
deprecatedMPropWarned = true;
|
||||||
|
console.warn('m.prop() is deprecated, please use m.stream() instead.');
|
||||||
|
}
|
||||||
|
return Stream.bind(this)(...args);
|
||||||
|
};
|
||||||
|
|
||||||
modifiedMithril.withAttr = withAttr;
|
modifiedMithril.withAttr = function (...args) {
|
||||||
|
if (!deprecatedMWithAttrWarned) {
|
||||||
|
deprecatedMWithAttrWarned = true;
|
||||||
|
console.warn("m.withAttr() is deprecated, please use flarum's withAttr util (flarum/utils/withAttr) instead.");
|
||||||
|
}
|
||||||
|
return withAttr.bind(this)(...args);
|
||||||
|
};
|
||||||
// END DEPRECATED MITHRIL 2 BC LAYER
|
// END DEPRECATED MITHRIL 2 BC LAYER
|
||||||
|
|
||||||
global.m = modifiedMithril;
|
global.m = modifiedMithril;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user