sn-redux
v3.4.3
Published
A set of redux actions, reducers and redux-ovbservable epics for Sense/Net ECM
Downloads
58
Readme
sn-redux
sn-redux is a convention driven way of building sensenet ECM applications using Redux. It contains all the action types, actions and reducers for built-in sensenet Actions and Functions.
sn-redux gives you a standard set of:
- action types: e.g. CREATE_CONTENT_SUCCESS
- actions: e.g. updateContentSuccess, updateContentFailure
- reducers: for the action types above e.g. updateContentSuccess
- epics: for streams of actions that are related to the same process e.g. createContentEpic
Installation on an existing sensenet ECM portal
Get the latest stable version with npm
npm install --save sn-redux
or from the GitHub repository and place the downloaded source into your project. If you want to use only the transpiled JavaScript modules, you can find them in the dist/src folder and import them like
var SN = require('/pathtomodule/sn-redux');
If you want to use the module types you can find them in the src folder. Import them the following way:
import { Actions } from 'sn-redux';
import { Content, ContentTypes, Repository } 'sn-client-js';
let repository = new Repository.SnRepository({
RepositoryUrl: 'http://path-to-your-portal.com',
});
const content = Content.Create({ Id: 123 }, ContentTypes.Task, repository);
store.dispatch(Actions.Delete(content, false));
Installation into an external app with node and npm
To install the latest stable version
npm install --save sn-redux
Create your sensenet ECM portal Repository to use. You can configure your Store to use this repository, when calling Store.ConfigureStore
import { Repository } from 'sn-client-js';
let repository = new Repository.SnRepository({
RepositoryUrl: 'http://path-to-your-portal.com',
});
const store = Store.configureStore(
myRootReducer,
myRootEpic, // If not set, the default will be 'Epics.rootEpic'
[middleware1, middleware2], // If not set, only the epicMiddleware will be used
persistedState, // Optional
repository // Optional. If not provided, a Repository with default values will be used
);
To enable your external app to send request against your sensenet ECM portal change your Portal.settings
. For further information about cross-origin resource sharing in sensenet ECM check this article.
Check your sensenet ECM portal's web.config and if the ODataServiceToken
is set, you can pass to your Repository as a config value on client side.
let repository = new Repository.SnRepository({
RepositoryUrl: 'http://path-to-your-portal.com',
ODataToken: 'MyODataServiceToken'
});
Import
CommonJS
var Content = require('sn-client-js').Content;
var Repository = require('sn-client-js').Repository;
var ContentTypes = require('sn-client-js').ContentTypes;
var Actions = require('sn-redux').Actions;
let repository = new Repository.SnRepository({
RepositoryUrl: 'http://path-to-your-portal.com',
});
var content = Content.Create({ Id: 123 }, ContentTypes.Task, repository);
store.dispatch(Actions.Delete(123, false));
Typescript
import { Actions } 'sn-redux';
import { Content, ContentTypes, Repository } 'sn-client-js';
let repository = new Repository.SnRepository({
RepositoryUrl: 'http://path-to-your-portal.com',
});
const content = Content.Create({ Id: 123 }, ContentTypes.Task, repository);
store.dispatch(Actions.Delete(content, false));
Building sn-redux
Building the project, running all the unit tests and the ts linter and get the code coverage report, use:
npm run build
Running tests
To execute all unit tests and generate coverage reports, use:
npm t
Examples
Combine custom reducer with the built-in ones
import { combineReducers } from 'redux';
import { Reducers } from 'sn-redux';
const sensenet = Reducers.sensenet;
const myReducer = combineReducers({
sensenet,
listByFilter
});
Creating a store
import { Store } from 'sn-redux';
import { Repository } from 'sn-client-js';
let repository = new Repository.SnRepository({
RepositoryUrl: 'http://path-to-your-portal.com',
});
const store = Store.configureStore(
myRootReducer,
myRootEpic, // If not set, the default will be 'Epics.rootEpic'
[middleware1, middleware2], // If not set, only the epicMiddleware will be used
persistedState, // Optional
repository // Optional. If not provided, a Repository with default values will be used
);
Using built-in actions
import { Content, Repository, ContentTypes } from 'sn-client-js';
import { Actions } from 'sn-redux';
let repository = new Repository.SnRepository({
RepositoryUrl: 'http://path-to-your-portal.com',
});
const parentPath = '/workspaces/Project/budapestprojectworkspace/tasks';
const content = Content.Create({
DisplayName: 'My first task'
}, ContentTypes.Task, repository);
dispatch(Actions.CreateContent(content))
Documentation
- sn-redux API Reference
- sn-client-js API reference
- About OData REST API in sensenet ECM
- About Built-in OData Actions and Function in sensenet ECM
- Todo App with React, Redux and sensenet ECM
Influences
- Redux
- Getting started with Redux - Awesome course from the creator of Redux, Dan Abramov.
- Building React Applications with Idiomatic Redux - Another great course of Dan Abramov about building apps with Redux.
- rxjs
- redux-observable