This package include some utilities used by Drieam LTI apps.
Table of Contents
Getting Started
Installation
Install the @drieam/common and
its dependencies.
yarn add @drieam/common @drieam/api @drieam/models @drieam/ui
Usage
import { connectActions, connectReducers } from "@drieam/api";
import { User } from "../models";
import { setStore } from "@drieam/common";
type API = {
user: User
};
type Store = RootReducer<{
api: ConnectReducers<API>
}>;
const api: ApiRoutes<API> = {
user: {
onError,
path: "/lti/proxy/api/v1/users/:id?",
mapper: User,
list: true
}
};
const actions = connectActions < API > api;
const rootReducer = connectReducers < API > api;
const store = setStore(
api,
rootReducer,
[
],
defaultOptions
)({
});
Read the full API Documentation
Components
setStore(...) => Store
Create a redux store.
- Arguments:
api
(ReactRoutes
): Rest API configuration.rootReducer
(Reducer
): Root combined reducers.extraMiddlewares
(Middleware[]
): Array of redux middlewares.options
(object
): Configuration options.
import { setStore } from '@drieam/common';
...
type Store = RootReducer<{
api: ConnectReducers<API>;
}>;
...
const store = setStore(
api,
rootReducer,
[],
defaultOptions,
)({
});
- Return
Store
: The redux store.
Options
General settings of an action as an extension of api actions.
{
withErrorHandler: true,
csrfToken: getCSRFToken(),
history: createBrowserHistory(),
toasts: {
offline: {
duration: 0,
message: 'Not connected.',
},
save: { message: 'Saved success.' },
delete: { message: 'Deleted success.' },
},
};
}
- Attributes:
withErrorHandler
(boolean
): Enables ErrorHandlingMiddleware (Default: true
). Provides feedback through an Antd Notification on offline, save success or fail action.toasts
(object
): Notification settings, you can express which message can be provided by the error handler.history
(object
): history
is a JavaScript library that lets you easily manage session history anywhere JavaScript runs. (default: require 'history'
).csfrToken
(string
): Cross-site request forgery token. (Default: <meta [name="csrf-token"] />
).- Api options