Skip to content

Documentation

StormArmy edited this page Aug 3, 2021 · 2 revisions

Documentation

The namespace of Reply is listed as following:

Reply {
    CreateServerStore;
    CreateClientStore;
}

The following paragraphs will explain the two functions' usage.


CreateServerStore

Example:

CreateServerStore<IServerState,TServerActions,ISharedState,TSharedActions>(
    ServerReducer: Reducer<IServerState, IServerActions>,
    SharedReducer: Reducer<ISharedState, TSharedActions>,
    DefaultState: IServerStateS,
    DefaultSharedState: ISharedState,
    OnSharedActionDispatched: (DispatchedAction: TSharedActions) => void,
    Middleware?: ReadonlyMiddleware<IServerState, IServerActions>,
)

OnSharedActionDispatched's example:

const OnSharedActionDispatched = (Action) => {
    yourRemote.SendToAllPlayers(Action);
}

CreateClientStore

Example:

export function CreateClientStore<IClientState,TClientActions,ISharedState,TSharedActions>(
    ClientReducer: Reducer<IClientState, TClientActions>,
    SharedReducer: Reducer<ISharedState, TSharedActions>,
    DefaultState: IClientState,
    DefaultSharedState: ISharedState,
    Middleware?: ReadonlyMiddleware<IClientState, TClientActions>,
)

In order to synchronize the _Shared property of the client with the server's, you should create a function with the similar functionality to the following codes:

YourRemote.Connect((shared_action) => {
    ClientStore.Dispatch({
        type : "_OnSharedDispatched",
        Action : shared_action,
    });
})

It is also your duty to initialize client default state upon the join of the player.

AsyncFunction.CallServerAsync().then((state) => {
    ClientStore.Dispatch({ type: "RefreshShared", state: v });
    //Register to the shared action dispatched event
})

(This is the current documentation for Reply, I may add more details in the future.)

Clone this wiki locally