From 2ac2edbbadff9a09273479fadc5a344c7309ecca Mon Sep 17 00:00:00 2001 From: Matthew Kilgore Date: Fri, 7 Aug 2020 19:59:45 -0400 Subject: [PATCH] Replace mithril-stream with mithril/stream, set it as a global via m.stream --- js/package-lock.json | 5 ----- js/package.json | 1 - js/src/common/utils/patchMithril.js | 18 ++++++++++-------- js/src/forum/components/ForgotPasswordModal.js | 3 +-- js/src/forum/components/LogInModal.js | 7 +++---- js/src/forum/components/SignUpModal.js | 7 +++---- 6 files changed, 17 insertions(+), 24 deletions(-) diff --git a/js/package-lock.json b/js/package-lock.json index 7bc732533..3fa41bc49 100644 --- a/js/package-lock.json +++ b/js/package-lock.json @@ -3816,11 +3816,6 @@ "resolved": "https://registry.npmjs.org/mithril/-/mithril-2.0.4.tgz", "integrity": "sha512-mgw+DMZlhMS4PpprF6dl7ZoeZq5GGcAuWnrg5e12MvaGauc4jzWsDZtVGRCktsiQczOEUr2K5teKbE5k44RlOg==" }, - "mithril-stream": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/mithril-stream/-/mithril-stream-2.0.0.tgz", - "integrity": "sha512-7anPud4n2FMGIXBQATVpFzclkddXHmJ1TzlqOP9STybk8JZYOPAD2otMYiMDc6sPrTNDY5S6GPDlYNIUY8Qs3Q==" - }, "mixin-deep": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.2.tgz", diff --git a/js/package.json b/js/package.json index bb62d0880..4b7534524 100644 --- a/js/package.json +++ b/js/package.json @@ -15,7 +15,6 @@ "lodash-es": "^4.17.14", "m.attrs.bidi": "github:tobscure/m.attrs.bidi", "mithril": "^2.0.4", - "mithril-stream": "^2.0.0", "punycode": "^2.1.1", "spin.js": "^3.1.0", "webpack": "^4.43.0", diff --git a/js/src/common/utils/patchMithril.js b/js/src/common/utils/patchMithril.js index 61d0227d1..425eae2ad 100644 --- a/js/src/common/utils/patchMithril.js +++ b/js/src/common/utils/patchMithril.js @@ -1,20 +1,20 @@ -import Component from '../Component'; +import Stream from 'mithril/stream'; export default function patchMithril(global) { - const mo = global.m; + const defaultMithril = global.m; - const m = function (comp, ...args) { - const node = mo.apply(this, arguments); + const modifiedMithril = function (comp, ...args) { + const node = defaultMithril.apply(this, arguments); if (!node.attrs) node.attrs = {}; if (node.attrs.bidi) { - m.bidi(node, node.attrs.bidi); + modifiedMithril.bidi(node, node.attrs.bidi); } if (node.attrs.route) { node.attrs.href = node.attrs.route; - node.attrs.tag = m.route.Link; + node.attrs.tag = modifiedMithril.route.Link; delete node.attrs.route; } @@ -22,7 +22,9 @@ export default function patchMithril(global) { return node; }; - Object.keys(mo).forEach((key) => (m[key] = mo[key])); + Object.keys(defaultMithril).forEach((key) => (modifiedMithril[key] = defaultMithril[key])); - global.m = m; + modifiedMithril.stream = Stream; + + global.m = modifiedMithril; } diff --git a/js/src/forum/components/ForgotPasswordModal.js b/js/src/forum/components/ForgotPasswordModal.js index f8fc9aac9..7c73458cc 100644 --- a/js/src/forum/components/ForgotPasswordModal.js +++ b/js/src/forum/components/ForgotPasswordModal.js @@ -1,4 +1,3 @@ -import Stream from 'mithril-stream'; import Modal from '../../common/components/Modal'; import Button from '../../common/components/Button'; import extractText from '../../common/utils/extractText'; @@ -20,7 +19,7 @@ export default class ForgotPasswordModal extends Modal { * * @type {Function} */ - this.email = Stream(this.attrs.email || ''); + this.email = m.stream(this.attrs.email || ''); /** * Whether or not the password reset email was sent successfully. diff --git a/js/src/forum/components/LogInModal.js b/js/src/forum/components/LogInModal.js index 411657337..f05e0ef9d 100644 --- a/js/src/forum/components/LogInModal.js +++ b/js/src/forum/components/LogInModal.js @@ -1,4 +1,3 @@ -import Stream from 'mithril-stream'; import Modal from '../../common/components/Modal'; import ForgotPasswordModal from './ForgotPasswordModal'; import SignUpModal from './SignUpModal'; @@ -24,21 +23,21 @@ export default class LogInModal extends Modal { * * @type {Function} */ - this.identification = Stream(this.attrs.identification || ''); + this.identification = m.stream(this.attrs.identification || ''); /** * The value of the password input. * * @type {Function} */ - this.password = Stream(this.attrs.password || ''); + this.password = m.stream(this.attrs.password || ''); /** * The value of the remember me input. * * @type {Function} */ - this.remember = Stream(!!this.attrs.remember); + this.remember = m.stream(!!this.attrs.remember); } className() { diff --git a/js/src/forum/components/SignUpModal.js b/js/src/forum/components/SignUpModal.js index 31622b89c..9b1b37d4d 100644 --- a/js/src/forum/components/SignUpModal.js +++ b/js/src/forum/components/SignUpModal.js @@ -1,4 +1,3 @@ -import Stream from 'mithril-stream'; import Modal from '../../common/components/Modal'; import LogInModal from './LogInModal'; import Button from '../../common/components/Button'; @@ -25,21 +24,21 @@ export default class SignUpModal extends Modal { * * @type {Function} */ - this.username = Stream(this.attrs.username || ''); + this.username = m.stream(this.attrs.username || ''); /** * The value of the email input. * * @type {Function} */ - this.email = Stream(this.attrs.email || ''); + this.email = m.stream(this.attrs.email || ''); /** * The value of the password input. * * @type {Function} */ - this.password = Stream(this.attrs.password || ''); + this.password = m.stream(this.attrs.password || ''); } className() {