Skip to content
This repository has been archived by the owner on Jan 10, 2018. It is now read-only.

Commit

Permalink
fix(deps): Fixed peer dependencies to support Angular 4.x (#395)
Browse files Browse the repository at this point in the history
* Revert "WIP: Provide fractal state management (#269)"

This reverts commit 32c0fe0.

* fix(deps): Fixed peer dependencies to support Angular 4.x

Also fixed test setup
  • Loading branch information
brandonroberts committed Apr 20, 2017
1 parent 108dc0e commit b1b142c
Show file tree
Hide file tree
Showing 34 changed files with 1,426 additions and 1,571 deletions.
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -10,7 +10,7 @@ RxJS powered state management for Angular applications, inspired by Redux
on top of Angular. Core tenets:
- State is a single immutable data structure
- Actions describe state changes
- Pure functions called reducers take previous slices of state and the next action to compute the new state
- Pure functions called reducers take the previous state and the next action to compute the new state
- State accessed with the `Store`, an observable of state and an observer of actions

These core principles enable building components that can use the `OnPush` change detection strategy
Expand Down Expand Up @@ -57,7 +57,7 @@ export const INCREMENT = 'INCREMENT';
export const DECREMENT = 'DECREMENT';
export const RESET = 'RESET';

export function counterReducer(state: number = 0, action: Action): number {
export function counterReducer(state: number = 0, action: Action) {
switch (action.type) {
case INCREMENT:
return state + 1;
Expand All @@ -74,7 +74,7 @@ export function counterReducer(state: number = 0, action: Action): number {
}
```

In your app's main module, import those reducers and use the `StoreModule.forRoot(reducers)`
In your app's main module, import those reducers and use the `StoreModule.provideStore(reducers)`
function to provide them to Angular's injector:

```ts
Expand All @@ -85,7 +85,7 @@ import { counterReducer } from './counter';
@NgModule({
imports: [
BrowserModule,
StoreModule.forRoot({ counter: counterReducer })
StoreModule.provideStore({ counter: counterReducer })
]
})
export class AppModule {}
Expand Down
Empty file removed docs/action-reducers.md
Empty file.
Empty file removed docs/actions.md
Empty file.
Empty file removed docs/store-module.md
Empty file.
Empty file removed docs/store.md
Empty file.
14 changes: 6 additions & 8 deletions index.ts
@@ -1,8 +1,6 @@
import * as __private_export__ from './src/private_export';

export { Action, ActionReducer, ActionReducerMap, ActionReducerFactory } from './src/models';
export { StoreModule } from './src/store_module';
export { Store } from './src/store';
export { combineReducers, compose } from './src/utils';
export { __private_export__ };

export * from './src/dispatcher';
export * from './src/ng2';
export * from './src/reducer';
export * from './src/state';
export * from './src/store';
export * from './src/utils';
48 changes: 31 additions & 17 deletions karma.conf.js
@@ -1,4 +1,5 @@
var path = require('path');
var webpack = require('webpack');

module.exports = function(karma) {
'use strict';
Expand Down Expand Up @@ -29,6 +30,10 @@ module.exports = function(karma) {
]
},

mime: {
'text/x-typescript': ['ts', 'tsx']
},

browsers: ['Chrome'],

port: 9018,
Expand All @@ -41,29 +46,26 @@ module.exports = function(karma) {
webpack: {
devtool: 'inline-source-map',
resolve: {
root: __dirname,
extensions: ['', '.ts', '.js']
extensions: ['.ts', '.js']
},
module: {
preLoaders: [
loaders: [
{
enforce: 'pre',
test: /\.ts$/,
loader: 'tslint-loader',
exclude: [
/node_modules/
]
}
],
loaders: [
},
{
test: /\.ts?$/,
exclude: /(node_modules)/,
loader: 'ts'
}
],
postLoaders: [
loader: 'awesome-typescript-loader'
},
{
test: /\.(js|ts)$/, loader: 'istanbul-instrumenter',
enforce: 'post',
test: /\.(js|ts)$/, loader: 'istanbul-instrumenter-loader',
include: path.resolve(__dirname, 'src'),
exclude: [
/\.(e2e|spec|bundle)\.ts$/,
Expand All @@ -72,11 +74,23 @@ module.exports = function(karma) {
}
]
},
tslint: {
emitErrors: false,
failOnHint: false,
resourcePath: 'src'
}
plugins: [
new webpack.LoaderOptionsPlugin({
options: {
tslint: {
emitErrors: false,
failOnHint: false,
resourcePath: 'src'
}
}
}),
new webpack.ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
path.resolve('src'),
{}
)
]
}
});
};
};
71 changes: 31 additions & 40 deletions package.json
Expand Up @@ -6,8 +6,7 @@
"module": "./index.js",
"scripts": {
"karma": "karma start --single-run",
"test:unit": "node tests.js",
"test:unit:coverage": "nyc npm run test:unit",
"test:unit": "npm run karma",
"test:ngc": "ngc -p ./spec/ngc/tsconfig.ngc.json",
"test": "npm run test:unit && npm run test:ngc",
"clean:pre": "rimraf release",
Expand Down Expand Up @@ -36,50 +35,42 @@
},
"homepage": "https://github.com/ngrx/store#readme",
"peerDependencies": {
"@angular/core": "4.0.0-rc.1",
"@ngrx/core": "^1.1.0",
"rxjs": "^5.0.0"
"@angular/core": "^2.0.0 || ^4.0.0",
"rxjs": "^5.0.0-beta.12",
"@ngrx/core": "^1.1.0"
},
"devDependencies": {
"@angular/common": "4.0.0-rc.1",
"@angular/compiler": "4.0.0-rc.1",
"@angular/compiler-cli": "4.0.0-rc.1",
"@angular/core": "4.0.0-rc.1",
"@angular/http": "4.0.0-rc.1",
"@angular/platform-browser": "4.0.0-rc.1",
"@angular/platform-browser-dynamic": "4.0.0-rc.1",
"@angular/platform-server": "4.0.0-rc.1",
"@angular/common": "^2.0.0",
"@angular/compiler": "^2.0.0",
"@angular/compiler-cli": "^2.0.0",
"@angular/core": "^2.0.0",
"@angular/platform-browser": "^2.0.0",
"@angular/platform-browser-dynamic": "^2.0.0",
"@angular/platform-server": "^2.0.0",
"@ngrx/core": "^1.2.0",
"@types/jasmine": "^2.5.42",
"@types/node": "^7.0.5",
"awesome-typescript-loader": "^3.0.4-rc.2",
"@types/jasmine": "^2.2.33",
"@types/node": "^6.0.38",
"awesome-typescript-loader": "^3.0.0",
"core-js": "^2.4.1",
"cpy-cli": "^1.0.1",
"istanbul-instrumenter-loader": "^2.0.0",
"jasmine": "^2.5.3",
"jasmine-marbles": "^0.0.2",
"nyc": "^10.1.2",
"istanbul-instrumenter-loader": "^0.2.0",
"jasmine": "^2.5.0",
"karma": "^1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.0.2",
"karma-mocha-reporter": "^2.1.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.0",
"rimraf": "^2.5.4",
"rollup": "^0.41.4",
"rxjs": "^5.1.0",
"ts-loader": "^2.0.0",
"ts-node": "^2.1.0",
"tslint": "^4.4.2",
"tslint-loader": "^3.3.0",
"typescript": "^2.1.6",
"rollup": "^0.34.13",
"rxjs": "^5.0.0-beta.11",
"ts-loader": "^0.8.2",
"tslint": "^3.15.1",
"tslint-loader": "^2.1.5",
"typescript": "^2.0.2",
"uglifyjs": "^2.4.10",
"webpack": "^2.2.1",
"zone.js": "^0.7.6"
},
"nyc": {
"extension": [
".ts"
],
"exclude": [
"spec/**/*.spec"
],
"include": [
"src/**/*.ts"
]
"webpack": "^2.1.0-beta.21",
"zone.js": "^0.7.2"
}
}
29 changes: 20 additions & 9 deletions spec/edge.spec.ts
@@ -1,7 +1,8 @@
import { Observable } from 'rxjs/Observable';
import { todos, todoCount } from './fixtures/edge_todos';
import { createInjector } from './helpers/injector';
import { Store, StoreModule } from '../';
import {ReflectiveInjector} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {todos, todoCount} from './fixtures/edge_todos';

import {Store, StoreModule, Dispatcher, State, Action, combineReducers} from '../';


interface TestAppSchema {
Expand All @@ -13,32 +14,41 @@ interface TestAppSchema {
interface Todo { }

interface TodoAppSchema {
todoCount: number;
visibilityFilter: string;
todos: Todo[];
}



describe('ngRx Store', () => {
describe('basic store actions', () => {
let store: Store<TodoAppSchema>;

describe('basic store actions', function() {

let injector: ReflectiveInjector;
let store: Store<TestAppSchema>;
let dispatcher: Dispatcher;

beforeEach(() => {
const injector = createInjector(StoreModule.forRoot<TodoAppSchema>({ todos, todoCount }));

injector = ReflectiveInjector.resolveAndCreate([
StoreModule.provideStore({ todos, todoCount }).providers
]);

store = injector.get(Store);
dispatcher = injector.get(Dispatcher);
});

it('should provide an Observable Store', () => {
expect(store).toBeDefined();
});

it('should handle re-entrancy', (done) => {

let todosNextCount = 0;
let todosCountNextCount = 0;

store.select('todos').subscribe((todos: any[]) => {
todosNextCount++;
todosNextCount++
store.dispatch({ type: 'SET_COUNT', payload: todos.length })
});

Expand All @@ -55,6 +65,7 @@ describe('ngRx Store', () => {
expect(todosCountNextCount).toBe(2);
done();
}, 10);

});
});
});
16 changes: 5 additions & 11 deletions spec/fixtures/todos.ts
@@ -1,9 +1,3 @@
export interface TodoItem {
id: number;
completed: boolean;
text: string;
}

export const ADD_TODO = 'ADD_TODO';
export const COMPLETE_TODO = 'COMPLETE_TODO';
export const SET_VISIBILITY_FILTER = 'SET_VISIBILITY_FILTER';
Expand All @@ -26,7 +20,7 @@ export function visibilityFilter(state = VisibilityFilters.SHOW_ALL, {type, payl
}
};

export function todos(state: TodoItem[] = [], {type, payload}): TodoItem[] {
export function todos(state = [], {type, payload}) {
switch (type) {
case ADD_TODO:
return [
Expand All @@ -38,11 +32,11 @@ export function todos(state: TodoItem[] = [], {type, payload}): TodoItem[] {
}
];
case COMPLETE_ALL_TODOS:
return state.map(todo => ({ ...todo, completed: true }));
return state.map(todo => Object.assign({}, todo, {completed: true}));
case COMPLETE_TODO:
return state.map(todo =>
todo.id === payload.id ? { ...todo, completed: true } : todo
);
return state.map(todo => {
return todo.id === payload.id ? Object.assign({}, todo, {completed: true}) : todo;
});
default:
return state;
}
Expand Down
18 changes: 0 additions & 18 deletions spec/helpers/injector.ts

This file was deleted.

0 comments on commit b1b142c

Please sign in to comment.