Skip to content

Commit

Permalink
Add methods to handle state data in action logs. Bump to 1.0.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
brochington committed Dec 22, 2016
1 parent e32ac51 commit 8eb87db
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,13 @@ export default class MyComponent extends React.Component {
}
}
```


## Staction instance methods

### Logging

- `staction.enableLogging()` - enable logging of each action call to console.
- `staction.disableLogging()` - disable logging of actions to console.
- `staction.disableStateWhenLogging()` - do not include current state when action logs.
- `staction.enableStateWhenLogging()` - include current state in action logs.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "staction",
"version": "0.0.7",
"version": "1.0.0",
"description": "A straightforward method of managing state, with support for Promises, Generators, and Async/Await.",
"main": "build/bundle.js",
"scripts": {
Expand Down
21 changes: 17 additions & 4 deletions src/Staction.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Staction {
_privateActions: Object
_state: any
_stateSetCallback: Function
_loggingEnabled = true
_addStateToLogs = false

init(actions: Object, initFunc: (o: Object) => Object, stateSetCallback: Function) {
// attach Staction to window for debugging
Expand Down Expand Up @@ -74,7 +76,13 @@ class Staction {
actionWrapper(name: string, func: Function, ...args: any): Promise<*> {
// call the action function with correct args.
if (this._loggingEnabled) {
console.log("action: ", name, this._state);
if (this._addStateToLogs) {
console.log("action: ", name, this._state);
}

else {
console.log("action: ", name);
}
}

const newState = func(() => this._state, this._wrappedActions, ...args);
Expand Down Expand Up @@ -144,9 +152,6 @@ class Staction {
this._stateSetCallback(this._state, this._wrappedActions);
};

// _loggingEnabled = process.env.NODE_ENV == 'development' ? true : false;
_loggingEnabled = true;

/* Debugging assist methods */
enableLogging = () => {
this._loggingEnabled = true;
Expand All @@ -157,6 +162,14 @@ class Staction {
this._loggingEnabled = false;
return `Staction logging is disabled`;
}

disableStateWhenLogging = () => {
this._addStateToLogs = false
}

enableStateWhenLogging = () => {
this._addStateToLogs = true
}
}

export default Staction;

0 comments on commit 8eb87db

Please sign in to comment.