
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
angular-redux
Advanced tools
Redux helpers for Angular 2
Install via npm
npm install angular-redux
ManagedReducer-class works as a construction object for a store reducer.
constructor(identifier: string, intialState:any, actionHandlers?:Map<string, Function>[])
addActionHandler(identifier: string, handler:Function) => this: ManagedReducer
addActionHandlers(actionHandlers:Map<string, Function>) => this: ManagedReducer
setInitialState(initialState:any) => this: ManagedReducer
create() => reducer: Function
The following example instantiates a reducer for the stateObject-key in root-state.
new ManagedReducer('stateObject', [])
.addActionHandlers({
...
'ACTION_IDENTIFIER': (state:any, action:IAction) => {
...
return state;
}
...
})
ManagedStore-class works as a construction singleton-object for a redux store.
The store configuration is done via the static initialize
-function.
static initialize(callback) => store: Store
static destroy() => void
The following instance properties are available while configuring the store instance
in the initialize
callback.
initialState: any
middleware: List<Middleware>
getStore() => store: Store
addReducer(managedReducer:ManagedReducer) => this: ManagedStore
addReducers(managedReducers:ManagedReducer[]) => this: ManagedStore
Example store initialization
const store = ManagedStore.initialize(instance => {
instance.initialState = initialState;
instance.addReducers([
...
]);
});
The Connector-class is used to connect Angular components into the store context. The class prototype consists of three functions, two of which are used only internally during the connector lifecycle.
mapAndValidateState(state:any, mapStateToScope:Function) => newState: any
updateTarget(target:any, state:any, dispatch:Dispatch) => void
map(mapStateToTarget?:Function, mapDispatchToTarget?:Function) => {connect:Function, store:Store}
The map
function is used to hook the connector with state mapping functions. The returned object contains the
connect-function which is used to assign the updated state and mapped actions to the target-object. It also
contains the redux store which can be used after instantiating the Connector.
connect(target:Function|Object) => unsubscribe: Function
As shown, connecting the mapped state to a target function or a target object return the unsubscribe-callback for cleaning up the connection after target disposal.
The REDUX_PROVIDERS
injectable simply provides the application context with a Connector
factory to be used
in components and directives.
import {bootstrap} from 'angular2/platform/browser';
import {REDUX_PROVIDERS} from 'angular-redux';
import {RootComponent} from "./components/root.component";
bootstrap(
RootComponent,
[
...
REDUX_PROVIDERS
]
);
Minimum required configuration of a store consists of the initial state and at least one reducer.
const initialState = {
...
};
const store = ManagedStore.initialize(instance => {
instance.initialState = initialState;
instance.addReducers([
...
]);
});
@ConnectToStore(
state => Map().set('genres', state.get('genres')),
dispatch => bindActionCreators(actions, dispatch)
)
export class StoreComponent {
...
}
@ConnectToStore()
export class StoreComponent {
...
mapDispatchToTarget(dispatch) {
return bindActionCreators(actions, dispatch);
}
mapStateToTarget(state) {
return Map().set('genres', state.get('genres'));
}
...
}
export class StoreComponent {
constructor(connector: Connector) {
const storeConnector = connector.map(
state => Map().set('genres', state.get('genres')),
dispatch => bindActionCreators(actions, dispatch)
);
storeConnector.connect(this);
this.store = storeConnector.store;
}
...
}
FAQs
Redux helpers for Angular 2
The npm package angular-redux receives a total of 5 weekly downloads. As such, angular-redux popularity was classified as not popular.
We found that angular-redux demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.