From b1693f9537e91c940deaddabe8eeb5657185d29a Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Mon, 1 Jun 2015 10:26:23 +0930 Subject: [PATCH] Add 'state helpers', shortcuts to make querying app state easier --- framework/core/js/forum/src/app.js | 2 ++ .../js/forum/src/initializers/state-helpers.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 framework/core/js/forum/src/initializers/state-helpers.js diff --git a/framework/core/js/forum/src/app.js b/framework/core/js/forum/src/app.js index 9aa36238f..d68d374ef 100644 --- a/framework/core/js/forum/src/app.js +++ b/framework/core/js/forum/src/app.js @@ -1,5 +1,6 @@ import App from 'flarum/utils/app'; import store from 'flarum/initializers/store'; +import stateHelpers from 'flarum/initializers/state-helpers'; import discussionControls from 'flarum/initializers/discussion-controls'; import postControls from 'flarum/initializers/post-controls'; import preload from 'flarum/initializers/preload'; @@ -12,6 +13,7 @@ import boot from 'flarum/initializers/boot'; var app = new App(); app.initializers.add('store', store); +app.initializers.add('state-helpers', stateHelpers); app.initializers.add('discussion-controls', discussionControls); app.initializers.add('post-controls', postControls); app.initializers.add('session', session); diff --git a/framework/core/js/forum/src/initializers/state-helpers.js b/framework/core/js/forum/src/initializers/state-helpers.js new file mode 100644 index 000000000..3363a6ff6 --- /dev/null +++ b/framework/core/js/forum/src/initializers/state-helpers.js @@ -0,0 +1,14 @@ +import ReplyComposer from 'flarum/components/reply-composer'; +import DiscussionPage from 'flarum/components/discussion-page'; + +export default function(app) { + app.composingReplyTo = function(discussion) { + return this.composer.component instanceof ReplyComposer && + this.composer.component.props.discussion === discussion; + }; + + app.viewingDiscussion = function(discussion) { + return this.current instanceof DiscussionPage && + this.current.discussion() === discussion; + }; +};