- #508 (thanks to @ratoaq2)
- #463 (thanks to @draccoz)
- Add a way to return a false value from a method decorated with
@dispatch
to allow conditionally preventing a dispatch. PR#497
@dispatch()
selectTab(tab) {
return this.active.id !== tab.id ? { type: .... } : false;
}
- Add a way to access the decorated instance inside of transformer for
@select$
PR#500
@Input() public anotherInput: string;
@select$(['selector'], (obs$, inst) => obs$.filter(x => x.name === inst.anotherInput))
public selectedObs: Observable<any>;
Shout out to contributors:
- There are no functional changes / fixes in this release.
There was accidental publish to the @latest
tag with an experimental fix for the v6 branch that got pushed out with the incorrect tag.
For some clarity:
- v7+ - currently only works with Angular 5+
- v6+ - works with Angular 4 and earlier, and v5.
- v8 - this was an accidental version bump - and that package is now deprecated.
Use @angular-redux/store@^7
- this version supports Angular 5, and also changes to using lettable operators.
Any new major releases will released on the v7 branch and with the @latest
tag for final publishes.
Use @angular-redux/store@^6
- This supports Angular 4 and earlier.
Where possible, I will be maintaining and applying any fixes / enhancements for v7 into v6 where it does not introduce a breaking change.
I made a few mistakes trying to publish fixes / etc to two major versions, which caused some releases to get tagged incorrectly and caused some confusion. Sorry for any confusion this has caused, and will do better on avoiding this in the future, and being more transparent with the releases that are going out.
- Add Angular 5+ as peer dependency
- Update dependencies to Angular 5
- Update RxJS to 5.5.2 and use lettable operators
- Update peer dependencies to only Angular 5+
note: This version requires Angular 5, the code generated by the compiler is not compatible with Angular v4.
- Update peer dependency to include Angular 5, note - this is a beta release, if you run into any issues with Angular 5 please let me know. This release is still using an older version of angular to build / compile, but seems to work with Angular 5.
Working on a V7 release that upgrades to be built/use Angular 5 core/compiler/etc which produces builds that are not backwards compatable with Angular 4. More details will be available soon.
- Fixed issue with AppRef.tick being called recurisvly #443
- Turn tsconfig checks to 11.
- Minor code cleanup - no feature changes.
- Update toolchain to typescript 2.4.
- Fix for angular-redux#434.
- Fix for angular-redux#427: memory leaks introduced in 6.3.0.
** You'll want to grab this update! **
- Handle
@WithSubStore
,.configureSubStore
boundary cases for when the base path doesn't exist in the store yet.
- Docgen updates.
- Allow
@WithSubStore
's base path to be dynamic.
- Enabled fractal store features for the decorator interface. See https://github.com/angular-redux/store/blob/master/articles/fractal-store.md for details.
- Fix a boundary condition where
MockNgRedux
could get instantiated twice under certain conditions. - Adjust exposed interfaces of
MockNgRedux
andNgRedux
to make them structurally compatible (both assignable to theNgRedux
type) (issue #419) - Update to TypeScript 2.3.4
- Improve packaging of
testing
submodule for people working in strict mode (thanks @ialibhay)!
- Reset
MockNgRedux.mockInstance
as part ofMockNgRedux.reset()
.
- Fixed some issues with MockNgRedux and the select dectorators. See angular-redux#413 for details.
- Fixed a memory leak with
@select
,@select$
. See angular-redux/example-app#34 for details.
- Added 'fractal store' support.
You can now create an encapsulated 'sub-store' that only operates on a section of the global Redux store:
const subStore = ngRedux.configureSubStore(
['path', 'to', 'somewhere'],
localReducer)
Substore has the same interface as NgRedux
: select
, dispatch
etc;
however when these functions are called on a substore instance, they
are scoped to the data under path.to.somewhere
.
See the docs for more info.
- Fixed issues with middlewares that allow dispatching of things other than just raw actions (e.g. redux-thunk) [#386, #264].
- Fixed issues with enhancers that change the way
Store.subscribe
and listeners work (e.g. redux-batch) [#372]
- Added the
@select$
decorator which allows you to attach observable operator chains directly to@select
. For example:
import { select$ } from 'angular-redux/store';
export const debounceAndTriple = obs$ => obs$
.debounce(300)
.map(x => 3 * x);
class Foo {
@select$(['foo', 'bar'], debounceAndTriple)
readonly debouncedFooBar$: Observable<number>;
}
- Added the
@dispatch
decorator which allows auto-dispatch for your action creators. For example:
import { Injectable } from '@angular/core';
import { Action } from 'redux';
@Injectable()
export class AnimalActions {
static readonly LOAD_ANIMALS = 'LOAD_ANIMALS';
// Calling loadAnimals will now automagically dispatch the action.
@dispatch()
loadAnimals = (animalType: AnimalType): Action => ({
type: AnimalActions.LOAD_ANIMALS,
meta: { animalType },
})
// ...
}
- Reset
MockNgRedux.mockInstance
as part ofMockNgRedux.reset()
.
Issue #370
- More code cleanup
- Auto-generated API documentation.
- Added
NgReduxTestingModule
,MockNgRedux
to help unit test components and services that select from the store. See here for details. - Expose
PathSelector
,FunctionSelector
, andPropertySelector
types inindex.d.ts
.
- Simplified build toolchain
- Simplified unit testing toolchain
- Consolidated repo-specific examples in to the example-app repo.
Both version 2 and 4 of Angular are now supported. However Angular 2 support is deprecated and will be removed in the next major version.
Documentation updates; no code change. Added a 'getting started' tutorial.
Due to the impending release of Angular4, the name 'ng2-redux' no longer makes a ton of sense. The Angular folks have moved to a model where all versions are just called 'Angular', and we should match that.
After discussion with the other maintainers, we decided that since we have to rename things anyway, this is a good opportunity to collect ng2-redux and its related libraries into a set of scoped packages. This will allow us to grow the feature set in a coherent but decoupled way.
As of v6, the following packages are deprecated:
- ng2-redux
- ng2-redux-router
- ng2-redux-form
Those packages will still be available on npm for as long as they are being used.
However we have published the same code under a new package naming scheme:
- @angular-redux/store (formerly ng2-redux)
- @angular-redux/router (formerly ng2-redux-router)
- @angular-redux/form (formerly ng2-redux-form).
We have also decided that it's easier to reason about things if these packages align at least on major versions. So everything has at this point been bumped to 6.0.0.
Apart from the rename, the following API changes are noted:
- @angular-redux/store: none.
- @angular-redux/router: none.
- @angular-redux/form:
NgReduxForms
renamed toNgReduxFormModule
for consistency.
Applied fix addressing #309 - select function called even if state does not change.
You can now get an observable to the root state by passing no arguments to
ngRedux.select
:
private this.rootState$: Observable<IAppState>;
constructor(ngRedux: NgRedux) {
this.rootState$ = ngRedux.select();
}
ngRedux.dispatch()
has been tweaked to always run in the Angular zone. This
should prevent unexpected weirdness when dispatching from callbacks to 3rd-party
libraries. See #259 for further discussion.
- Refactored the example app a bit to split out the different selector demos instead of lumping most of them into the counter component.
- Miscellaneous documentation updates.
- Fix for the
ERROR in NgReduxModule is not an NgModule
error thrown by Angular CLI. - Remove deprecations.
- Breaking changes associated with Angular 2.4+.
- Minimum Angular peer dependency is now 2.4.0
- Removed support for the
connect
pattern: it's simply not a good fit for Angular. You should be using theselect
pattern now. - Remove deprecated constructor arg for
NgRedux
. - Minimum Angular peer dependency is now 2.4.0
NgReduxModule.forRoot
is no more. Now just importNgReduxModule
directly.
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { NgReduxModule } from 'ng2-redux';
@NgModule({
declarations: [
AppComponent
],
imports: [
NgReduxModule.forRoot(),
BrowserModule,
],
providers: [],
bootstrap: [AppComponent]
})
class AppModule {
// etc.
}
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { NgReduxModule } from 'ng2-redux';
@NgModule({
declarations: [
AppComponent
],
imports: [
NgReduxModule,
BrowserModule,
],
providers: [],
bootstrap: [AppComponent]
})
class AppModule {
// etc.
}
Recovery release that restores the functionality of 4.2.2. Use this release if you're on Angular < 2.2. If your on Angular >= 2.3, you'll need to use [email protected] (see v5.x branch for the changelog) to consume the fix for #282 (due to a breaking change in Angular).
Botched releases - don't use. Apologies; I've added a prepublish
script to npm
to prevent this from happening again.
- #281 (DevToolsExtension missing from providers list)
- #221 (type error with redux-thunk)
- #228 ('generic' error with AoT)
- #251 (No provider for DevToolsExtension)
- Better support for Angular CLI
- NgModule interface changes to better support Angular 2's ahead-of-time compiler (AoT)
- Update build to use ngc - metadata.json is now produced
- Introduced NgReduxModule
- Fix AoT related bugs #247, #235, #228
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { NgReduxModule, NgRedux } from 'ng2-redux';
import { IAppState } from './appstate';
import { rootReducer } from './store';
@NgModule({
declarations: [
AppComponent
],
imports: [
NgReduxModule,
BrowserModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
constructor(ngRedux: NgRedux<IAppState>) {
ngRedux.configureStore(rootReducer,{});
}
}
before
import { select } from 'ng2-redux';
export class MyComponent {
@select() thing$:Observable<string>;
}
after
import { NgRedux } from 'ng2-redux';
export class MyComponent {
thing$: Observable<string>;
constructor(private ngRedux:NgRedux<MyAppState>) {
}
ngOnInit() {
this.thing$ = this.ngRedux.select (n => n.thing);
}
}
- Temp update to npm build to uninstall typings for chai/sinon-chai so
/// <reference types="chai" />
doesn't get added to files.
- Manual fix of build to remove chai type reference
- Improved error if trying to dispatch before store is configured - #118, #198
- Relax Zone JS version - #189, #187
- Fix DevTools being out of sync for actions dispatched from tool, #192
- Upgrade to TypeScript 2 - #189, #190
- Add Code Coverage - #193, #206, #207
- Update redux peer dependency to 3.5.0
- observable shim which we depend on was introduced in 3.5.0, not 3.4.0
- Update to RC5 (#184, fixes #183)
- Include src in npm package (#182, fixes #180)
- Fix window in Universal (#185, fixes #172)
- Fix window is undefined in Universal (#178, fixes #172)
- Change seamless immutable integration to not need conditional require (#169)
- Argument to DevTools enhancer is now optional (#164)
- Decorator deletes key on target, not
this
. (#168, fixes #166)
- DevToolsExtension - convience wrapper for dev tools (#115)
- Select - seamless support for ImmutableJS (#160)
- Able to use
@select
in services - Behavior of
select
with chained dispatches, (fixes #149, #153)
- Added a
provideStore()
function which lets you pass in a already created store. It can be used as this:
Create your store:
// store.ts
import {
applyMiddleware,
Store,
combineReducers,
compose,
createStore
} from 'redux';
import thunk from 'redux-thunk';
import reduxLogger from 'redux-logger';
import { myReducer } from './reducers/my-reducer';
const rootReducer = combineReducers({
myReducer,
});
export const store = createStore(
rootReducer,
compose(
applyMiddleware(
thunk,
reduxLogger
)
)
) as Store
Create your App and call provideStore
with your newly created store:
// app.ts
import { NgRedux } from 'ng2-redux';
import { store } from './store.ts';
interface IAppState {
// ...
};
@Component({
// ... etc.
})
class App {
constructor(private ngRedux: NgRedux) {
this.ngRedux.provideStore(store);
}
// ...
}
-
Added a 'path' option to
ngRedux.select()
and@select()
. Now you can do stuff like@select(['foo', 'bar'])
to selectstate.foo.bar
into an observable. -
Add ability to provide custom comparer to @select decorator to keep consistent with ngRedux.select
import { is } from 'immutablejs'
export class SomeComponent {
@select(n=n.some.selector, is) someSelector$: Observable<any>
}
- AppliicationRef is optional dependency, fixes#127
This release introduces the new decorator interface. You can now use
@select
to create an observable from a slice of store state.
See 'the select pattern' in README.md for a complete description of how to use this new decorator.
You no longer need to manually subscribe and ApplicationRef.tick()
for Redux DevTools to work; we do this automatically for you.
We've changed how bootstrapping ng2-redux
works. The provider
function has gone away in favour of making NgRedux a first-class
@Injectable
.
You now configure your store in the constructor of your top-level app component instead of prior to bootstrapping. This allows the store to be configured with middleware and enhancers that rely on Angular 2 services, which previously was unnecessarily difficult.
bootstrap.ts:
import { bootstrap } from '@angular/platform-browser-dynamic';
import { createStore, applyMiddleware, compose } from 'redux';
import { NgRedux } from 'ng2-redux';
const createLogger = require('redux-logger');
const persistState = require('redux-localstorage');
import { rootReducer } from './reducers';
import { App } from './app';
// Confusing and hard to use with dependency injection.
const middleware = [ createLogger() ];
const enhancers = [ persistState('counter', { key: 'example-app' }) ];
const store = compose(
applyMiddleware(middleware),
...enhancers)
(createStore)(rootReducer);
bootstrap(App, [ provide(store) ])
app.ts
import { Component } from '@angular/core';
import { NgRedux } from 'ng2-redux';
@Component({
// ...
})
export class App {
constructor(private ngRedux: NgRedux) {}
}
bootstrap.ts:
import { bootstrap } from '@angular/platform-browser-dynamic';
import { NgRedux } from 'ng2-redux';
import { App } from './app';
bootstrap(App, [ Ng2Redux ]);
app.ts
import { Component } from '@angular/core';
import { NgRedux } from 'ng2-redux';
import { reduxLogger } from 'redux-logger';
import { initialState, rootReducer } from './reducers';
@Component({
// ...
})
export class App {
constructor(private ngRedux: NgRedux) {
const middleware = [ reduxLogger ];
const enhancers = [ persistState('counter', { key: 'example-app' }) ];
// Easier to understand, and can use middleware or enhancers from DI.
ngRedux.configureStore(rootReducer, initialState, middleware, enhancers);
}
}
The example app has been updated to use @select
and a
DI-aware action creator service (counter-actions.ts
). It now also
shows examples of using middleware and enhancers from the Redux
community: redux-logger
and redux-localstorage
.
- Type definitions:
- Ported to typescript
- Supports typed stores / reducers
- Uses offical Redux type definitions
- Type Injectable:
- Able to inject
NgRedux
into your component by type, and not need@Inject('ngRedux')
@Inject('ngRedux')
still works
- Able to inject
import { NgRedux } from 'ng2-redux';
// ...
export class MyComponent {
constructor(private ngRedux: NgRedux) {}
}
- State as Observable: Ability to expose parts of your state as an observable.
select<S>(selector: string | number | symbol | ((state: RootState) => S), comparer?: (x: any, y: any) => boolean): Observable<S>;
wrapActionCreators: (actions: any) => (dispatch: Redux.Dispatch<any>) => Redux.ActionCreator<{}> | Redux.ActionCreatorsMapObject;
Example use:
import { NgRedux } from 'ng2-redux';
// ...
export class MyComponent implements OnInit {
countByKey$: Observable<number>;
countByFunc$: Observable<number>;
constructor(private ngRedux: NgRedux) {
this.countByKey$ = this.ngRedux.select('count');
this.countByFunc$ = this.ngRedux.select(state=>state.count);
}
}
Also have the ability to provide a custom compare function.
import { is, Map } from 'immutable';
import { NgRedux } from 'ng2-redux';
// ...
export class MyComponent implements OnInit {
person$: Observable<Map<string,any>>;
constructor(private ngRedux: ngRedux) {
// even if the reference of the object has changed,
// if the data is the same - it wont be treated as a change
this.person$ = this.ngRedux.select(state=>state.people.get(0),is);
}
}