Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
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
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
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.