diff --git a/js/src/common/Component.ts b/js/src/common/Component.ts index 605ae69fe..85386c7b6 100644 --- a/js/src/common/Component.ts +++ b/js/src/common/Component.ts @@ -132,5 +132,35 @@ export default abstract class Component implemen * * This can be used to assign default values for missing, optional attrs. */ - protected static initAttrs(attrs: T): void {} + protected static initAttrs(attrs: T): void { + // Deprecated, part of Mithril 2 BC layer + this.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. + * + * @see https://mithril.js.org/components.html#passing-data-to-components + * + * @deprecated, use attrs instead. + */ + get props() { + return this.attrs; + } + set props(props) { + this.attrs = props; + } + + // END DEPRECATED MITHRIL 2 BC LAYER } diff --git a/js/src/common/utils/patchMithril.js b/js/src/common/utils/patchMithril.js index 7f0c595d0..bea9cf30f 100644 --- a/js/src/common/utils/patchMithril.js +++ b/js/src/common/utils/patchMithril.js @@ -1,5 +1,6 @@ import Stream from 'mithril/stream'; import extract from './extract'; +import withAttr from './withAttr'; export default function patchMithril(global) { const defaultMithril = global.m; @@ -68,5 +69,11 @@ export default function patchMithril(global) { modifiedMithril.route.Link = modifiedLink; + // BEGIN DEPRECATED MITHRIL 2 BC LAYER + modifiedMithril.prop = Stream; + + modifiedMithril.withAttr = withAttr; + // END DEPRECATED MITHRIL 2 BC LAYER + global.m = modifiedMithril; }