You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Introduced a new function called provideStore() which accepts a already created Redux store (angular-redux#142)
* feat: Introduced a new function called provideStore() which accepts a already created Redux store
This function accepts a already created Redux store so the users
can themselves create a store exactly how they want to do it.
The configureStore() function can also be used just like before.
* doc: Fix where constant variable is reassigned (angular-redux#141)
* doc: Fix where constant variable is reassigned
* fix: Update to import syntax in docs
* doc: Fix typos
* doc: Fix typos in changelog
* doc: Fix typos in readme
* doc: Fix typo in readme
Copy file name to clipboardExpand all lines: packages/store/README.md
+98-8
Original file line number
Diff line number
Diff line change
@@ -70,6 +70,62 @@ class App {
70
70
}
71
71
```
72
72
73
+
Or if you prefer to create the Redux store yourself you can do that and use the
74
+
`provideStore()` function instead.
75
+
76
+
Create your store:
77
+
```typescript
78
+
// store.ts
79
+
80
+
import {
81
+
applyMiddleware,
82
+
Store,
83
+
combineReducers,
84
+
compose,
85
+
createStore
86
+
} from'redux';
87
+
importthunkfrom'redux-thunk';
88
+
importreduxLoggerfrom'redux-logger';
89
+
90
+
import { myReducer } from'./reducers/my-reducer';
91
+
92
+
const rootReducer =combineReducers({
93
+
myReducer,
94
+
});
95
+
96
+
exportconst store =createStore(
97
+
rootReducer,
98
+
compose(
99
+
applyMiddleware(
100
+
thunk,
101
+
reduxLogger
102
+
)
103
+
)
104
+
) asStore
105
+
```
106
+
107
+
Create your App and call `provideStore` with your newly created store:
108
+
```typescript
109
+
// app.ts
110
+
111
+
import { NgRedux } from'ng2-redux';
112
+
import { store } from'./store.ts';
113
+
114
+
interfaceIAppState {
115
+
// ...
116
+
};
117
+
@Component({
118
+
// ... etc.
119
+
})
120
+
classApp {
121
+
constructor(privatengRedux:NgRedux) {
122
+
this.ngRedux.provideStore(store);
123
+
}
124
+
125
+
// ...
126
+
}
127
+
```
128
+
73
129
Now your Angular 2 app has been reduxified!
74
130
75
131
## Usage
@@ -85,19 +141,19 @@ preferred approach to accessing store data in Angular 2.
85
141
86
142
#### The @select decorator
87
143
88
-
The `@select` decorator can be added to the property of any class or angular
144
+
The `@select` decorator can be added to the property of any class or angular
89
145
component/injectable. It will turn the property into an observable which observes
90
146
the Redux Store value which is selected by the decorator's parameter.
91
147
92
148
The decorator expects to receive a `string`, an array of `string`s, a `function` or no
93
-
parameter at all.
149
+
parameter at all.
94
150
95
151
- If a `string` is passed the `@select` decorator will attempt to observe a store
96
152
property whose name matches the `string`.
97
153
- If an array of strings is passed, the decorator will attempt to match that path
98
154
through the store (similar to `immutableJS`'s `getIn`).
99
155
- If a `function` is passed the `@select` decorator will attempt to use that function
100
-
as a selector on the RxJs observable.
156
+
as a selector on the RxJs observable.
101
157
- If nothing is passed then the `@select` decorator will attempt to use the name of the class property to find a matching value in the Redux store. Note that a utility is in place here where any $ characters will be ignored from the class property's name.
0 commit comments