mirror of
https://github.com/element-hq/element-web
synced 2024-11-25 02:35:48 +03:00
Break out actions and payloads to their own files
The definitions take up a lot of space which makes it hard to see the dispatcher class, so break them out.
This commit is contained in:
parent
90a898d03f
commit
8c72c27da9
6 changed files with 87 additions and 52 deletions
|
@ -23,7 +23,7 @@ import { _t } from '../languageHandler';
|
||||||
import * as sdk from '../index';
|
import * as sdk from '../index';
|
||||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||||
import { Room } from "matrix-js-sdk/src/models/room";
|
import { Room } from "matrix-js-sdk/src/models/room";
|
||||||
import { AsyncActionPayload } from "../dispatcher/dispatcher";
|
import { AsyncActionPayload } from "../dispatcher/payloads";
|
||||||
|
|
||||||
export default class RoomListActions {
|
export default class RoomListActions {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,7 +18,7 @@ limitations under the License.
|
||||||
import Analytics from '../Analytics';
|
import Analytics from '../Analytics';
|
||||||
import { asyncAction } from './actionCreators';
|
import { asyncAction } from './actionCreators';
|
||||||
import TagOrderStore from '../stores/TagOrderStore';
|
import TagOrderStore from '../stores/TagOrderStore';
|
||||||
import { AsyncActionPayload } from "../dispatcher/dispatcher";
|
import { AsyncActionPayload } from "../dispatcher/payloads";
|
||||||
import { MatrixClient } from "matrix-js-sdk/src/client";
|
import { MatrixClient } from "matrix-js-sdk/src/client";
|
||||||
|
|
||||||
export default class TagOrderActions {
|
export default class TagOrderActions {
|
||||||
|
|
|
@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { AsyncActionPayload } from "../dispatcher/dispatcher";
|
import { AsyncActionPayload } from "../dispatcher/payloads";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an action thunk that will dispatch actions indicating the current
|
* Create an action thunk that will dispatch actions indicating the current
|
||||||
|
|
23
src/dispatcher/actions.ts
Normal file
23
src/dispatcher/actions.ts
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Dispatcher actions also extend into any arbitrary string, so support that.
|
||||||
|
export type DispatcherAction = Action | string;
|
||||||
|
|
||||||
|
export enum Action {
|
||||||
|
// TODO: Populate with actual actions
|
||||||
|
}
|
||||||
|
|
|
@ -17,55 +17,8 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Dispatcher } from "flux";
|
import { Dispatcher } from "flux";
|
||||||
|
import { Action } from "./actions";
|
||||||
export enum Action {
|
import { ActionPayload, AsyncActionPayload } from "./payloads";
|
||||||
// TODO: Populate with actual actions
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dispatcher actions also extend into any arbitrary string, so support that.
|
|
||||||
export type DispatcherAction = Action | string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The base dispatch type exposed by our dispatcher.
|
|
||||||
*/
|
|
||||||
export interface ActionPayload {
|
|
||||||
[property: string]: any; // effectively makes this 'extends Object'
|
|
||||||
action: DispatcherAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The function the dispatcher calls when ready for an AsyncActionPayload. The
|
|
||||||
* single argument is used to start a dispatch. First the dispatcher calls the
|
|
||||||
* outer function, then when the called function is ready it calls the cb
|
|
||||||
* function to issue the dispatch. It may call the callback repeatedly if needed.
|
|
||||||
*/
|
|
||||||
export type AsyncActionFn = (cb: (action: ActionPayload) => void) => void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An async version of ActionPayload
|
|
||||||
*/
|
|
||||||
export class AsyncActionPayload implements ActionPayload {
|
|
||||||
/**
|
|
||||||
* The function the dispatcher should call.
|
|
||||||
*/
|
|
||||||
public readonly fn: AsyncActionFn;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Not used on AsyncActionPayload.
|
|
||||||
*/
|
|
||||||
public get action(): DispatcherAction {
|
|
||||||
return "NOT_USED";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new AsyncActionPayload with the given ready function.
|
|
||||||
* @param {AsyncActionFn} readyFn The function to be called when the
|
|
||||||
* dispatcher is ready.
|
|
||||||
*/
|
|
||||||
public constructor(readyFn: AsyncActionFn) {
|
|
||||||
this.fn = readyFn;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A dispatcher for ActionPayloads (the default within the SDK).
|
* A dispatcher for ActionPayloads (the default within the SDK).
|
||||||
|
|
59
src/dispatcher/payloads.ts
Normal file
59
src/dispatcher/payloads.ts
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { DispatcherAction } from "./actions";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base dispatch type exposed by our dispatcher.
|
||||||
|
*/
|
||||||
|
export interface ActionPayload {
|
||||||
|
[property: string]: any; // effectively makes this 'extends Object'
|
||||||
|
action: DispatcherAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The function the dispatcher calls when ready for an AsyncActionPayload. The
|
||||||
|
* single argument is used to start a dispatch. First the dispatcher calls the
|
||||||
|
* outer function, then when the called function is ready it calls the cb
|
||||||
|
* function to issue the dispatch. It may call the callback repeatedly if needed.
|
||||||
|
*/
|
||||||
|
export type AsyncActionFn = (cb: (action: ActionPayload) => void) => void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An async version of ActionPayload
|
||||||
|
*/
|
||||||
|
export class AsyncActionPayload implements ActionPayload {
|
||||||
|
/**
|
||||||
|
* The function the dispatcher should call.
|
||||||
|
*/
|
||||||
|
public readonly fn: AsyncActionFn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Not used on AsyncActionPayload.
|
||||||
|
*/
|
||||||
|
public get action(): DispatcherAction {
|
||||||
|
return "NOT_USED";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new AsyncActionPayload with the given ready function.
|
||||||
|
* @param {AsyncActionFn} readyFn The function to be called when the
|
||||||
|
* dispatcher is ready.
|
||||||
|
*/
|
||||||
|
public constructor(readyFn: AsyncActionFn) {
|
||||||
|
this.fn = readyFn;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue