diff --git a/framework/core/js/src/common/Component.ts b/framework/core/js/src/common/Component.ts index 85386c7b6..a9d5e91b9 100644 --- a/framework/core/js/src/common/Component.ts +++ b/framework/core/js/src/common/Component.ts @@ -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 implemen */ protected static initAttrs(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(attrs: T): void {} - /** * The attributes passed into the component. * @@ -156,9 +154,17 @@ export default abstract class Component 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; } diff --git a/framework/core/js/src/common/utils/patchMithril.js b/framework/core/js/src/common/utils/patchMithril.js index bea9cf30f..d4e3963ad 100644 --- a/framework/core/js/src/common/utils/patchMithril.js +++ b/framework/core/js/src/common/utils/patchMithril.js @@ -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;