mirror of
https://github.com/flarum/framework.git
synced 2024-11-26 10:14:16 +08:00
Add warnings to Mithril 2 BC layer (#2313)
This commit is contained in:
parent
a6632fc1b4
commit
bfa62dbe8f
|
@ -1,5 +1,8 @@
|
|||
import * as Mithril from 'mithril';
|
||||
|
||||
let deprecatedPropsWarned = false;
|
||||
let deprecatedInitPropsWarned = false;
|
||||
|
||||
export type ComponentAttrs = {
|
||||
className?: string;
|
||||
|
||||
|
@ -134,20 +137,15 @@ export default abstract class Component<T extends ComponentAttrs = any> implemen
|
|||
*/
|
||||
protected static initAttrs<T>(attrs: T): void {
|
||||
// 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
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -156,9 +154,17 @@ export default abstract class Component<T extends ComponentAttrs = any> implemen
|
|||
* @deprecated, use attrs instead.
|
||||
*/
|
||||
get props() {
|
||||
if (!deprecatedPropsWarned) {
|
||||
deprecatedPropsWarned = true;
|
||||
console.warn('this.props is deprecated, please use this.attrs instead.');
|
||||
}
|
||||
return this.attrs;
|
||||
}
|
||||
set props(props) {
|
||||
if (!deprecatedPropsWarned) {
|
||||
deprecatedPropsWarned = true;
|
||||
console.warn('this.props is deprecated, please use this.attrs instead.');
|
||||
}
|
||||
this.attrs = props;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,9 @@ import Stream from 'mithril/stream';
|
|||
import extract from './extract';
|
||||
import withAttr from './withAttr';
|
||||
|
||||
let deprecatedMPropWarned = false;
|
||||
let deprecatedMWithAttrWarned = false;
|
||||
|
||||
export default function patchMithril(global) {
|
||||
const defaultMithril = global.m;
|
||||
|
||||
|
@ -70,9 +73,21 @@ export default function patchMithril(global) {
|
|||
modifiedMithril.route.Link = modifiedLink;
|
||||
|
||||
// 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
|
||||
|
||||
global.m = modifiedMithril;
|
||||
|
|
Loading…
Reference in New Issue
Block a user