mirror of
https://github.com/flarum/framework.git
synced 2025-01-19 16:02:44 +08:00
Add 'state helpers', shortcuts to make querying app state easier
This commit is contained in:
parent
220190cc53
commit
b1693f9537
|
@ -1,5 +1,6 @@
|
||||||
import App from 'flarum/utils/app';
|
import App from 'flarum/utils/app';
|
||||||
import store from 'flarum/initializers/store';
|
import store from 'flarum/initializers/store';
|
||||||
|
import stateHelpers from 'flarum/initializers/state-helpers';
|
||||||
import discussionControls from 'flarum/initializers/discussion-controls';
|
import discussionControls from 'flarum/initializers/discussion-controls';
|
||||||
import postControls from 'flarum/initializers/post-controls';
|
import postControls from 'flarum/initializers/post-controls';
|
||||||
import preload from 'flarum/initializers/preload';
|
import preload from 'flarum/initializers/preload';
|
||||||
|
@ -12,6 +13,7 @@ import boot from 'flarum/initializers/boot';
|
||||||
var app = new App();
|
var app = new App();
|
||||||
|
|
||||||
app.initializers.add('store', store);
|
app.initializers.add('store', store);
|
||||||
|
app.initializers.add('state-helpers', stateHelpers);
|
||||||
app.initializers.add('discussion-controls', discussionControls);
|
app.initializers.add('discussion-controls', discussionControls);
|
||||||
app.initializers.add('post-controls', postControls);
|
app.initializers.add('post-controls', postControls);
|
||||||
app.initializers.add('session', session);
|
app.initializers.add('session', session);
|
||||||
|
|
14
framework/core/js/forum/src/initializers/state-helpers.js
Normal file
14
framework/core/js/forum/src/initializers/state-helpers.js
Normal file
|
@ -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;
|
||||||
|
};
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user