Add in BC layer for props, initProps, m.withAttr, and m.prop (#2310)

This commit is contained in:
Alexander Skvortsov 2020-09-24 22:30:55 -04:00 committed by GitHub
parent aea8a3ff1f
commit 54ff6e720c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 1 deletions

View File

@ -132,5 +132,35 @@ export default abstract class Component<T extends ComponentAttrs = any> implemen
* *
* This can be used to assign default values for missing, optional attrs. * This can be used to assign default values for missing, optional attrs.
*/ */
protected static initAttrs<T>(attrs: T): void {} protected static initAttrs<T>(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<T>(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
} }

View File

@ -1,5 +1,6 @@
import Stream from 'mithril/stream'; import Stream from 'mithril/stream';
import extract from './extract'; import extract from './extract';
import withAttr from './withAttr';
export default function patchMithril(global) { export default function patchMithril(global) {
const defaultMithril = global.m; const defaultMithril = global.m;
@ -68,5 +69,11 @@ export default function patchMithril(global) {
modifiedMithril.route.Link = modifiedLink; 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; global.m = modifiedMithril;
} }