Skip to content

Commit

Permalink
Merge pull request #7 from KevinAst/initial
Browse files Browse the repository at this point in the history
publish: v0.1.0 Initial Release
  • Loading branch information
KevinAst authored Mar 6, 2018
2 parents c5d42f8 + 9fa136c commit e085aab
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 60 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: node_js
node_js:
- "6"
- "7"
- "8"
- node # current node version (may be duplicate, but that's OK)
script:
- npm run prepublish # lint, clean, build (bundles), test (bundles)
Expand Down
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,11 @@ run-time stack.


<!--- Badges for CI Builds --->
[![Build Status](https://travis-ci.org/KevinAst/feature-redux-logic.svg?branch=master)](https://travis-ci.org/KevinAst/feature-redux-logic)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/81530601c0f2449481882ac285add698)](https://www.codacy.com/app/KevinAst/feature-redux-logic?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=KevinAst/feature-redux-logic&amp;utm_campaign=Badge_Grade)
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/81530601c0f2449481882ac285add698)](https://www.codacy.com/app/KevinAst/feature-redux-logic?utm_source=github.com&utm_medium=referral&utm_content=KevinAst/feature-redux-logic&utm_campaign=Badge_Coverage)
[![Known Vulnerabilities](https://snyk.io/test/github/kevinast/feature-redux-logic/badge.svg?targetFile=package.json)](https://snyk.io/test/github/kevinast/feature-redux-logic?targetFile=package.json)
[![NPM Version Badge](https://img.shields.io/npm/v/feature-redux-logic.svg)](https://www.npmjs.com/package/feature-redux-logic)
<!--- TODO Badges
- CI Build: ?? WHEN CI Build In place
- GRADE: DONE (see above)
- CODE COV: ?? WHEN Code coverage in place
- Vulnerab: DONE (see above)
- NPM: DONE (see above)
--->


**Overview:**
Expand Down Expand Up @@ -295,7 +290,7 @@ your using redux-logic?_
You can change this behavior through the following configuration:
```js
logicAspect.allowNoLogic$ = true;
logicAspect.config.allowNoLogic$ = true;
```
With this option enabled, when no logic modules are found,
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"eslint": "^3.19.0",
"eslint-loader": "^1.7.1",
"eslint-plugin-react": "^7.6.1",
"feature-u": ">=0.1.0",
"jest": "^22.1.4",
"npm-run-all": "^4.0.2",
"redux-logic": ">=0.7.0",
Expand All @@ -101,6 +102,7 @@
},
"dependencies": {},
"peerDependencies": {
"feature-u": ">=0.1.0",
"redux-logic": ">=0.7.0"
}
}
50 changes: 15 additions & 35 deletions src/logicAspect.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {createLogicMiddleware} from 'redux-logic'; // peerDependency
import {createAspect,
extendAspectProperty,
launchApp} from 'feature-u'; // peerDependency:

// our logger (integrated/activated via feature-u)
Expand All @@ -9,35 +8,16 @@ const logf = launchApp.diag.logf.newLogger('- ***feature-redux-logic*** logicAsp
// NOTE: See README for complete description
export default createAspect({
name: 'logic',
genesis,
validateFeatureContent,
assembleFeatureContent,
createLogicMiddleware$,
getReduxMiddleware,
config: {
allowNoLogic$: false, // PUBLIC: client override to: true || [{logicModules}]
createLogicMiddleware$, // HIDDEN: createLogicMiddleware$(app, appLogic): reduxMiddleware
},
});


/**
* Register feature-redux-logic proprietary Aspect APIs (required to
* pass feature-u validation).
* This must occur early in the life-cycle (i.e. this method) to
* guarantee the new API is available during feature-u validation.
*
* @return {string} NONE FOR US ... an error message when self is in an invalid state
* (falsy when valid).
*
* @private
*/
function genesis() {
logf('genesis() registering internal Aspect properties');

extendAspectProperty('allowNoLogic$'); // Aspect.allowNoLogic$: true || [{logicModules}]
// ... AI: technically this is for reducerAspect only (if the API ever supports this)
extendAspectProperty('createLogicMiddleware$'); // Aspect.createLogicMiddleware$(app, appLogic): reduxMiddleware
// ... AI: technically this is for reducerAspect only (if the API ever supports this)
}


/**
* Validate self's aspect content on supplied feature.
*
Expand Down Expand Up @@ -97,23 +77,23 @@ function assembleFeatureContent(app, activeFeatures) {
else {

// by default, this is an error condition (when NOT overridden by client)
if (!this.allowNoLogic$) {
if (!this.config.allowNoLogic$) {
throw new Error('***ERROR*** feature-redux-logic found NO logic modules within your features ' +
`... did you forget to register Feature.${this.name} aspects in your features? ` +
'(please refer to the feature-redux-logic docs to see how to override this behavior).');
}

// when client override is an array, interpret it as logic modules
if (Array.isArray(this.allowNoLogic$)) {
logf.force('WARNING: NO logic modules were found in your Features (i.e. Feature.${this.name}), ' +
'but client override (logicAspect.allowNoLogic$=[{logicModules}];) ' +
if (Array.isArray(this.config.allowNoLogic$)) {
logf.force(`WARNING: NO logic modules were found in your Features (i.e. Feature.${this.name}), ` +
'but client override (logicAspect.config.allowNoLogic$=[{logicModules}];) ' +
'directed a continuation WITH specified logic modules.');
appLogic = this.allowNoLogic$;
appLogic = this.config.allowNoLogic$;
}
// otherwise, we simply disable redux-logic and continue on
else {
logf.force('WARNING: NO logic modules were found in your Features, ' +
'but client override (logicAspect.allowNoLogic$=true;) ' +
logf.force(`WARNING: NO logic modules were found in your Features (i.e. Feature.${this.name}), ` +
'but client override (logicAspect.config.allowNoLogic$=truthy;) ' +
'directed a continuation WITHOUT redux-logic.');
}
}
Expand All @@ -122,8 +102,8 @@ function assembleFeatureContent(app, activeFeatures) {
// ... conditionally when we have logic modules
// ... retained in self for promotion to feature-redux plugin
if (appLogic.length > 0) {
// ... accomplished in internal micro method (a defensive measure to allow easier overriding by client)
this.logicMiddleware = this.createLogicMiddleware$(app, appLogic);
// ... accomplished in internal config micro function (a defensive measure to allow easier overriding by client)
this.logicMiddleware = this.config.createLogicMiddleware$(app, appLogic);
}
// if we have no logic ... we have no middleware
else {
Expand All @@ -133,8 +113,8 @@ function assembleFeatureContent(app, activeFeatures) {


/**
* An internal micro method that creates/returns the redux middleware
* for redux-logic.
* An internal config micro function that creates/returns the
* redux middleware for redux-logic.
*
* This logic is broken out in this internal method as a defensive
* measure to make it easier for a client to override (if needed for
Expand Down
21 changes: 4 additions & 17 deletions src/spec/logicAspect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,6 @@ describe('logicAspect() tests', () => {
});


describe('genesis()', () => {

logicAspect.genesis();

const noOpTest = "can't access isAspectProperty() ... just running code :-(";
test('verify extendAspectProperty()', () => {
expect(noOpTest)
.toBe(noOpTest);
});

});


describe('validateFeatureContent()', () => {

test('must be an array', () => {
Expand Down Expand Up @@ -66,10 +53,10 @@ describe('logicAspect() tests', () => {

describe('no logic modules (OVERRIDE true)', () => {
beforeEach(() => {
logicAspect.allowNoLogic$ = true;
logicAspect.config.allowNoLogic$ = true;
});
afterEach(() => {
logicAspect.allowNoLogic$ = false;
logicAspect.config.allowNoLogic$ = false;
});
test('expecting getReduxMiddleware() to be null', () => {
logicAspect.assembleFeatureContent('simulated app', []);
Expand All @@ -80,10 +67,10 @@ describe('logicAspect() tests', () => {

describe('no logic modules (OVERRIDE array)', () => {
beforeEach(() => {
logicAspect.allowNoLogic$ = ['simulated', 'logic'];
logicAspect.config.allowNoLogic$ = ['simulated', 'logic'];
});
afterEach(() => {
logicAspect.allowNoLogic$ = false;
logicAspect.config.allowNoLogic$ = false;
});
test('expecting getReduxMiddleware() to be non-null', () => {
logicAspect.assembleFeatureContent('simulated app', []);
Expand Down

0 comments on commit e085aab

Please sign in to comment.