Put m.stream in flarum/utils/stream (#2316)

This commit is contained in:
Alexander Skvortsov 2020-09-27 23:49:33 -04:00 committed by GitHub
parent 63745b73aa
commit 4b679a35e0
16 changed files with 52 additions and 39 deletions

View File

@ -1,21 +1,21 @@
import Page from '../../common/components/Page'; import Page from '../../common/components/Page';
import Button from '../../common/components/Button'; import Button from '../../common/components/Button';
import Switch from '../../common/components/Switch'; import Switch from '../../common/components/Switch';
import Stream from '../../common/utils/Stream';
import EditCustomCssModal from './EditCustomCssModal'; import EditCustomCssModal from './EditCustomCssModal';
import EditCustomHeaderModal from './EditCustomHeaderModal'; import EditCustomHeaderModal from './EditCustomHeaderModal';
import EditCustomFooterModal from './EditCustomFooterModal'; import EditCustomFooterModal from './EditCustomFooterModal';
import UploadImageButton from './UploadImageButton'; import UploadImageButton from './UploadImageButton';
import saveSettings from '../utils/saveSettings'; import saveSettings from '../utils/saveSettings';
import withAttr from '../../common/utils/withAttr';
export default class AppearancePage extends Page { export default class AppearancePage extends Page {
oninit(vnode) { oninit(vnode) {
super.oninit(vnode); super.oninit(vnode);
this.primaryColor = m.stream(app.data.settings.theme_primary_color); this.primaryColor = Stream(app.data.settings.theme_primary_color);
this.secondaryColor = m.stream(app.data.settings.theme_secondary_color); this.secondaryColor = Stream(app.data.settings.theme_secondary_color);
this.darkMode = m.stream(app.data.settings.theme_dark_mode); this.darkMode = Stream(app.data.settings.theme_dark_mode);
this.coloredHeader = m.stream(app.data.settings.theme_colored_header); this.coloredHeader = Stream(app.data.settings.theme_colored_header);
} }
view() { view() {

View File

@ -5,6 +5,7 @@ import Button from '../../common/components/Button';
import saveSettings from '../utils/saveSettings'; import saveSettings from '../utils/saveSettings';
import ItemList from '../../common/utils/ItemList'; import ItemList from '../../common/utils/ItemList';
import Switch from '../../common/components/Switch'; import Switch from '../../common/components/Switch';
import Stream from '../../common/utils/Stream';
import withAttr from '../../common/utils/withAttr'; import withAttr from '../../common/utils/withAttr';
export default class BasicsPage extends Page { export default class BasicsPage extends Page {
@ -26,7 +27,7 @@ export default class BasicsPage extends Page {
this.values = {}; this.values = {};
const settings = app.data.settings; const settings = app.data.settings;
this.fields.forEach((key) => (this.values[key] = m.stream(settings[key]))); this.fields.forEach((key) => (this.values[key] = Stream(settings[key])));
this.localeOptions = {}; this.localeOptions = {};
const locales = app.data.locales; const locales = app.data.locales;

View File

@ -4,7 +4,7 @@ import Badge from '../../common/components/Badge';
import Group from '../../common/models/Group'; import Group from '../../common/models/Group';
import ItemList from '../../common/utils/ItemList'; import ItemList from '../../common/utils/ItemList';
import Switch from '../../common/components/Switch'; import Switch from '../../common/components/Switch';
import withAttr from '../../common/utils/withAttr'; import Stream from '../../common/utils/Stream';
/** /**
* The `EditGroupModal` component shows a modal dialog which allows the user * The `EditGroupModal` component shows a modal dialog which allows the user
@ -16,11 +16,11 @@ export default class EditGroupModal extends Modal {
this.group = this.attrs.group || app.store.createRecord('groups'); this.group = this.attrs.group || app.store.createRecord('groups');
this.nameSingular = m.stream(this.group.nameSingular() || ''); this.nameSingular = Stream(this.group.nameSingular() || '');
this.namePlural = m.stream(this.group.namePlural() || ''); this.namePlural = Stream(this.group.namePlural() || '');
this.icon = m.stream(this.group.icon() || ''); this.icon = Stream(this.group.icon() || '');
this.color = m.stream(this.group.color() || ''); this.color = Stream(this.group.color() || '');
this.isHidden = m.stream(this.group.isHidden() || false); this.isHidden = Stream(this.group.isHidden() || false);
} }
className() { className() {

View File

@ -5,7 +5,7 @@ import Alert from '../../common/components/Alert';
import Select from '../../common/components/Select'; import Select from '../../common/components/Select';
import LoadingIndicator from '../../common/components/LoadingIndicator'; import LoadingIndicator from '../../common/components/LoadingIndicator';
import saveSettings from '../utils/saveSettings'; import saveSettings from '../utils/saveSettings';
import withAttr from '../../common/utils/withAttr'; import Stream from '../../common/utils/Stream';
export default class MailPage extends Page { export default class MailPage extends Page {
oninit(vnode) { oninit(vnode) {
@ -25,7 +25,7 @@ export default class MailPage extends Page {
this.status = { sending: false, errors: {} }; this.status = { sending: false, errors: {} };
const settings = app.data.settings; const settings = app.data.settings;
this.fields.forEach((key) => (this.values[key] = m.stream(settings[key]))); this.fields.forEach((key) => (this.values[key] = Stream(settings[key])));
app app
.request({ .request({
@ -40,7 +40,7 @@ export default class MailPage extends Page {
for (const driver in this.driverFields) { for (const driver in this.driverFields) {
for (const field in this.driverFields[driver]) { for (const field in this.driverFields[driver]) {
this.fields.push(field); this.fields.push(field);
this.values[field] = m.stream(settings[field]); this.values[field] = Stream(settings[field]);
} }
} }

View File

@ -1,5 +1,6 @@
import Modal from '../../common/components/Modal'; import Modal from '../../common/components/Modal';
import Button from '../../common/components/Button'; import Button from '../../common/components/Button';
import Stream from '../../common/utils/Stream';
import saveSettings from '../utils/saveSettings'; import saveSettings from '../utils/saveSettings';
export default class SettingsModal extends Modal { export default class SettingsModal extends Modal {
@ -35,7 +36,7 @@ export default class SettingsModal extends Modal {
} }
setting(key, fallback = '') { setting(key, fallback = '') {
this.settings[key] = this.settings[key] || m.stream(app.data.settings[key] || fallback); this.settings[key] = this.settings[key] || Stream(app.data.settings[key] || fallback);
return this.settings[key]; return this.settings[key];
} }

View File

@ -12,6 +12,7 @@ import anchorScroll from './utils/anchorScroll';
import RequestError from './utils/RequestError'; import RequestError from './utils/RequestError';
import abbreviateNumber from './utils/abbreviateNumber'; import abbreviateNumber from './utils/abbreviateNumber';
import * as string from './utils/string'; import * as string from './utils/string';
import Stream from './utils/Stream';
import SubtreeRetainer from './utils/SubtreeRetainer'; import SubtreeRetainer from './utils/SubtreeRetainer';
import setRouteWithForcedRefresh from './utils/setRouteWithForcedRefresh'; import setRouteWithForcedRefresh from './utils/setRouteWithForcedRefresh';
import extract from './utils/extract'; import extract from './utils/extract';
@ -85,6 +86,7 @@ export default {
'utils/extract': extract, 'utils/extract': extract,
'utils/ScrollListener': ScrollListener, 'utils/ScrollListener': ScrollListener,
'utils/stringToColor': stringToColor, 'utils/stringToColor': stringToColor,
'utils/Stream': Stream,
'utils/subclassOf': subclassOf, 'utils/subclassOf': subclassOf,
'utils/setRouteWithForcedRefresh': setRouteWithForcedRefresh, 'utils/setRouteWithForcedRefresh': setRouteWithForcedRefresh,
'utils/patchMithril': patchMithril, 'utils/patchMithril': patchMithril,

View File

@ -0,0 +1,3 @@
import Stream from 'mithril/stream';
export default Stream;

View File

@ -1,6 +1,6 @@
import Stream from 'mithril/stream';
import extract from './extract'; import extract from './extract';
import withAttr from './withAttr'; import withAttr from './withAttr';
import Stream from './Stream';
let deprecatedMPropWarned = false; let deprecatedMPropWarned = false;
let deprecatedMWithAttrWarned = false; let deprecatedMWithAttrWarned = false;
@ -68,15 +68,13 @@ export default function patchMithril(global) {
Object.keys(defaultMithril).forEach((key) => (modifiedMithril[key] = defaultMithril[key])); Object.keys(defaultMithril).forEach((key) => (modifiedMithril[key] = defaultMithril[key]));
modifiedMithril.stream = Stream;
modifiedMithril.route.Link = modifiedLink; modifiedMithril.route.Link = modifiedLink;
// BEGIN DEPRECATED MITHRIL 2 BC LAYER // BEGIN DEPRECATED MITHRIL 2 BC LAYER
modifiedMithril.prop = function (...args) { modifiedMithril.prop = modifiedMithril.stream = function (...args) {
if (!deprecatedMPropWarned) { if (!deprecatedMPropWarned) {
deprecatedMPropWarned = true; deprecatedMPropWarned = true;
console.warn('m.prop() is deprecated, please use m.stream() instead.'); console.warn('m.prop() is deprecated, please use the Stream util (flarum/utils/Streams) instead.');
} }
return Stream.bind(this)(...args); return Stream.bind(this)(...args);
}; };

View File

@ -1,5 +1,6 @@
import Modal from '../../common/components/Modal'; import Modal from '../../common/components/Modal';
import Button from '../../common/components/Button'; import Button from '../../common/components/Button';
import Stream from '../../common/utils/Stream';
/** /**
* The `ChangeEmailModal` component shows a modal dialog which allows the user * The `ChangeEmailModal` component shows a modal dialog which allows the user
@ -21,14 +22,14 @@ export default class ChangeEmailModal extends Modal {
* *
* @type {function} * @type {function}
*/ */
this.email = m.stream(app.session.user.email()); this.email = Stream(app.session.user.email());
/** /**
* The value of the password input. * The value of the password input.
* *
* @type {function} * @type {function}
*/ */
this.password = m.stream(''); this.password = Stream('');
} }
className() { className() {

View File

@ -1,5 +1,6 @@
import ComposerBody from './ComposerBody'; import ComposerBody from './ComposerBody';
import extractText from '../../common/utils/extractText'; import extractText from '../../common/utils/extractText';
import Stream from '../../common/utils/Stream';
/** /**
* The `DiscussionComposer` component displays the composer content for starting * The `DiscussionComposer` component displays the composer content for starting
@ -26,7 +27,7 @@ export default class DiscussionComposer extends ComposerBody {
oninit(vnode) { oninit(vnode) {
super.oninit(vnode); super.oninit(vnode);
this.composer.fields.title = this.composer.fields.title || m.stream(''); this.composer.fields.title = this.composer.fields.title || Stream('');
/** /**
* The value of the title input. * The value of the title input.

View File

@ -4,6 +4,7 @@ import GroupBadge from '../../common/components/GroupBadge';
import Group from '../../common/models/Group'; import Group from '../../common/models/Group';
import extractText from '../../common/utils/extractText'; import extractText from '../../common/utils/extractText';
import ItemList from '../../common/utils/ItemList'; import ItemList from '../../common/utils/ItemList';
import Stream from '../../common/utils/Stream';
/** /**
* The `EditUserModal` component displays a modal dialog with a login form. * The `EditUserModal` component displays a modal dialog with a login form.
@ -14,17 +15,17 @@ export default class EditUserModal extends Modal {
const user = this.attrs.user; const user = this.attrs.user;
this.username = m.stream(user.username() || ''); this.username = Stream(user.username() || '');
this.email = m.stream(user.email() || ''); this.email = Stream(user.email() || '');
this.isEmailConfirmed = m.stream(user.isEmailConfirmed() || false); this.isEmailConfirmed = Stream(user.isEmailConfirmed() || false);
this.setPassword = m.stream(false); this.setPassword = Stream(false);
this.password = m.stream(user.password() || ''); this.password = Stream(user.password() || '');
this.groups = {}; this.groups = {};
app.store app.store
.all('groups') .all('groups')
.filter((group) => [Group.GUEST_ID, Group.MEMBER_ID].indexOf(group.id()) === -1) .filter((group) => [Group.GUEST_ID, Group.MEMBER_ID].indexOf(group.id()) === -1)
.forEach((group) => (this.groups[group.id()] = m.stream(user.groups().indexOf(group) !== -1))); .forEach((group) => (this.groups[group.id()] = Stream(user.groups().indexOf(group) !== -1)));
} }
className() { className() {

View File

@ -1,6 +1,7 @@
import Modal from '../../common/components/Modal'; import Modal from '../../common/components/Modal';
import Button from '../../common/components/Button'; import Button from '../../common/components/Button';
import extractText from '../../common/utils/extractText'; import extractText from '../../common/utils/extractText';
import Stream from '../../common/utils/Stream';
/** /**
* The `ForgotPasswordModal` component displays a modal which allows the user to * The `ForgotPasswordModal` component displays a modal which allows the user to
@ -19,7 +20,7 @@ export default class ForgotPasswordModal extends Modal {
* *
* @type {Function} * @type {Function}
*/ */
this.email = m.stream(this.attrs.email || ''); this.email = Stream(this.attrs.email || '');
/** /**
* Whether or not the password reset email was sent successfully. * Whether or not the password reset email was sent successfully.

View File

@ -5,6 +5,7 @@ import Button from '../../common/components/Button';
import LogInButtons from './LogInButtons'; import LogInButtons from './LogInButtons';
import extractText from '../../common/utils/extractText'; import extractText from '../../common/utils/extractText';
import ItemList from '../../common/utils/ItemList'; import ItemList from '../../common/utils/ItemList';
import Stream from '../../common/utils/Stream';
/** /**
* The `LogInModal` component displays a modal dialog with a login form. * The `LogInModal` component displays a modal dialog with a login form.
@ -23,21 +24,21 @@ export default class LogInModal extends Modal {
* *
* @type {Function} * @type {Function}
*/ */
this.identification = m.stream(this.attrs.identification || ''); this.identification = Stream(this.attrs.identification || '');
/** /**
* The value of the password input. * The value of the password input.
* *
* @type {Function} * @type {Function}
*/ */
this.password = m.stream(this.attrs.password || ''); this.password = Stream(this.attrs.password || '');
/** /**
* The value of the remember me input. * The value of the remember me input.
* *
* @type {Function} * @type {Function}
*/ */
this.remember = m.stream(!!this.attrs.remember); this.remember = Stream(!!this.attrs.remember);
} }
className() { className() {

View File

@ -1,5 +1,6 @@
import Modal from '../../common/components/Modal'; import Modal from '../../common/components/Modal';
import Button from '../../common/components/Button'; import Button from '../../common/components/Button';
import Stream from '../../common/utils/Stream';
/** /**
* The 'RenameDiscussionModal' displays a modal dialog with an input to rename a discussion * The 'RenameDiscussionModal' displays a modal dialog with an input to rename a discussion
@ -10,7 +11,7 @@ export default class RenameDiscussionModal extends Modal {
this.discussion = this.attrs.discussion; this.discussion = this.attrs.discussion;
this.currentTitle = this.attrs.currentTitle; this.currentTitle = this.attrs.currentTitle;
this.newTitle = m.stream(this.currentTitle); this.newTitle = Stream(this.currentTitle);
} }
className() { className() {

View File

@ -4,6 +4,7 @@ import Button from '../../common/components/Button';
import LogInButtons from './LogInButtons'; import LogInButtons from './LogInButtons';
import extractText from '../../common/utils/extractText'; import extractText from '../../common/utils/extractText';
import ItemList from '../../common/utils/ItemList'; import ItemList from '../../common/utils/ItemList';
import Stream from '../../common/utils/Stream';
/** /**
* The `SignUpModal` component displays a modal dialog with a singup form. * The `SignUpModal` component displays a modal dialog with a singup form.
@ -24,21 +25,21 @@ export default class SignUpModal extends Modal {
* *
* @type {Function} * @type {Function}
*/ */
this.username = m.stream(this.attrs.username || ''); this.username = Stream(this.attrs.username || '');
/** /**
* The value of the email input. * The value of the email input.
* *
* @type {Function} * @type {Function}
*/ */
this.email = m.stream(this.attrs.email || ''); this.email = Stream(this.attrs.email || '');
/** /**
* The value of the password input. * The value of the password input.
* *
* @type {Function} * @type {Function}
*/ */
this.password = m.stream(this.attrs.password || ''); this.password = Stream(this.attrs.password || '');
} }
className() { className() {

View File

@ -1,4 +1,5 @@
import subclassOf from '../../common/utils/subclassOf'; import subclassOf from '../../common/utils/subclassOf';
import Stream from '../../common/utils/Stream';
import ReplyComposer from '../components/ReplyComposer'; import ReplyComposer from '../components/ReplyComposer';
class ComposerState { class ComposerState {
@ -74,7 +75,7 @@ class ComposerState {
this.onExit = null; this.onExit = null;
this.fields = { this.fields = {
content: m.stream(''), content: Stream(''),
}; };
/** /**