@@ -4,6 +4,10 @@ var isEqual = require('lodash.isequal');
4
4
var setJ5Components = require ( '../actions/j5ReduxActions' ) . setJ5Components ;
5
5
var addJ5Components = require ( '../actions/j5ReduxActions' ) . addJ5Components ;
6
6
7
+ /**
8
+ * The j5-redux class instantiates Johnny Five components and sets up a reference to them in
9
+ * the redux store with a default state.
10
+ */
7
11
8
12
var initializers = {
9
13
/**
@@ -50,7 +54,7 @@ var initializers = {
50
54
* Get what's stored in redux for this class
51
55
* @param {string } store_name key everything in the class is stored under
52
56
* @param {string } id j5_object id
53
- * @return {object } redux state
57
+ * @returns {object } redux state
54
58
*/
55
59
getStore : function ( store_name , id ) {
56
60
var state = store . getState ( ) ;
@@ -84,7 +88,7 @@ var initializers = {
84
88
} ;
85
89
86
90
/**
87
- * J5Components
91
+ * J5Redux
88
92
* @param {object } spec object
89
93
* @param {object } spec.five - an object containing a Johnny five class & an array
90
94
* arguments to instantiate it
@@ -153,13 +157,13 @@ var initializers = {
153
157
}
154
158
}
155
159
}
156
- * @returns {Class J5Component } J5Component class
160
+ * @returns {Class J5Redux } J5Redux class
157
161
*/
158
162
159
163
160
- var Component = function ( spec ) {
161
- if ( ! ( this instanceof Component ) ) {
162
- return new Component ( ) ;
164
+ var J5Redux = function ( spec ) {
165
+ if ( ! ( this instanceof J5Redux ) ) {
166
+ return new J5Redux ( ) ;
163
167
}
164
168
// set up cache ----------------------------
165
169
this . state_cache = { } ;
@@ -190,30 +194,38 @@ var Component = function(spec) {
190
194
191
195
} ;
192
196
193
- Component . prototype = {
197
+ J5Redux . prototype = {
194
198
/**
195
199
* Get All j5 Components created inside here
196
200
* note: if you manipulate them outside of redux state managment
197
201
* the state will be out of sync
198
- * @return {object } - {j5Id: j5Component}
202
+ * @returns {object } - {j5Id: j5Component}
199
203
*/
200
204
getJ5Objects : function ( ) {
201
205
return this . j5_objects ;
202
206
} ,
203
207
/**
204
208
* Get the redux store values created in here. Helpful for debugging
205
209
* @param {string } j5_object_id - retrieve by id
206
- * @return {object } - redux state
210
+ * @returns {object } - redux state
207
211
*/
208
212
getState : function ( j5_object_id ) {
209
213
if ( j5_object_id ) {
210
214
return store . getState ( 'J5' ) [ this . store_name ] [ j5_object_id ] ;
211
215
}
212
216
return store . getState ( 'J5' ) [ this . store_name ] ;
213
217
} ,
218
+ /**
219
+ * log out state for debugging
220
+ * @returns {void }
221
+ */
214
222
log : function ( ) {
215
223
console . log ( this . getState ( ) ) ;
216
224
} ,
225
+ /**
226
+ * Reset redux state to defaults
227
+ * @returns {void }
228
+ */
217
229
resetReduxState : function ( ) {
218
230
var fiveIDArray = Object . keys ( this . j5_objects ) ;
219
231
var defaults = this . default_store ;
@@ -225,7 +237,7 @@ Component.prototype = {
225
237
226
238
// if test mode add initializer object to the export so I can test it :)
227
239
if ( process . env . IS_TEST_MODE ) {
228
- Component . initializers = initializers ;
240
+ J5Redux . initializers = initializers ;
229
241
}
230
242
231
- module . exports = Component ;
243
+ module . exports = J5Redux ;
0 commit comments