From 8832ea06667fdf353e3df6733aeddf873c7a6d6a Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com> Date: Thu, 24 Sep 2020 22:30:55 -0400 Subject: [PATCH] Add in BC layer for props, initProps, m.withAttr, and m.prop (#2310) --- framework/core/js/src/common/Component.ts | 32 ++++++++++++++++++- .../core/js/src/common/utils/patchMithril.js | 7 ++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/framework/core/js/src/common/Component.ts b/framework/core/js/src/common/Component.ts index 605ae69fe..85386c7b6 100644 --- a/framework/core/js/src/common/Component.ts +++ b/framework/core/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/framework/core/js/src/common/utils/patchMithril.js b/framework/core/js/src/common/utils/patchMithril.js index 7f0c595d0..bea9cf30f 100644 --- a/framework/core/js/src/common/utils/patchMithril.js +++ b/framework/core/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; }