Skip to content

Commit

Permalink
Merge branch 'release/v0.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienEtienne committed Apr 12, 2017
2 parents a46f60a + 87c0cea commit a7671e4
Show file tree
Hide file tree
Showing 14 changed files with 236 additions and 138 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,5 +4,6 @@
coverage
dist
docs/dist
doc
node_modules
npm-debug.log
16 changes: 15 additions & 1 deletion CHANGELOG.md
Expand Up @@ -2,6 +2,19 @@

All notable changes to this project will be documented in this file.

### [Unreleased][unreleased]

### [v0.0.2] - 2017-04-12

#### Improvement

- Remove property "defaultValue" in ActionInput.
- Add Documentation.

#### Fix

- Debug when create interactor with combo value empty.

### [v0.0.1] - 2016-12-01

- Create unique addAction function to add action.
Expand All @@ -14,6 +27,7 @@ All notable changes to this project will be documented in this file.
- Recover an interactor
- Interactor and action validation

[unreleased]: https://github.com/AdrienEtienne/actions-interactor/compare/v0.0.1...HEAD
[unreleased]: https://github.com/AdrienEtienne/actions-interactor/compare/v0.0.2...HEAD
[v0.0.2]: https://github.com/AdrienEtienne/actions-interactor/compare/v0.0.1...v0.0.2
[v0.0.1]: https://github.com/AdrienEtienne/actions-interactor/compare/v0.0.0...v0.0.1
[v0.0.0]: https://github.com/AdrienEtienne/actions-interactor/compare/5bdd04c...v0.0.0
9 changes: 9 additions & 0 deletions conf.json
@@ -0,0 +1,9 @@
{
"source": {
"include": ["./README.md", "./src"]
},
"opts": {
"destination": "doc",
"recurse": true
}
}
44 changes: 31 additions & 13 deletions docs/how-to-use.md
Expand Up @@ -4,7 +4,7 @@
## Example

```
import actionsInteractor from 'actions-interactor';
import actionsInteractor, {Types} from 'actions-interactor';
interactor = actionsInteractor.create({
name:'My interactor',
description:'My description'
Expand All @@ -17,6 +17,12 @@ console.log(interactor);
// actions:[]
// }
interactor.addAction({
name:'Name'
description:'Description',
type: Types.ACTION_BASE
})
```

## API
Expand All @@ -28,6 +34,21 @@ interactor object :
* description: String,
* actions: [Action](#action)[]

## <a name="action_type">ACTION_TYPE</a>
```
import {Types} from 'actions-interactor';
```

- ACTION_BASE:
- name: `String`
- description: `String`
- ACTION_INPUT: as ACTION_BASE plus
- required: `Boolean`
- defaultValue: `String`
- ACTION_COMBO: as ACTION_BASE plus
- required: `Boolean`
- choices: `Array`

## Classes

### <a name="interactor">Interactor</a>
Expand All @@ -44,20 +65,17 @@ interactor object :

Return true if all actions are valid.

##### addInfo(name: String, description: String): boolean

Add an action "information" to the list of actions
Return true if action added.

##### addInput(name: String, description: String[, required: boolean, defaultValue: :string]): boolean

Add an action "input box" to the list of actions
Return true if action added.
##### addAction(obj: Object)

##### addCombo(name: String, description: String, required: boolean, choices: Choice[]): boolean
Add an action to the list of actions

Add an action "combo" to the list of actions
Return true if action added.
obj :
- name: `String`
- description: `String`
- type: [`ACTION_TYPE`](#action_type)
- required: `Boolean`
- defaultValue: `String`,
- choices: `Array`

### <a name="action">Action</a>

Expand Down
6 changes: 4 additions & 2 deletions package.json
@@ -1,7 +1,7 @@
{
"private": true,
"name": "actions-interactor",
"version": "0.0.1",
"version": "0.0.2",
"description": "Managing interactions with validation of the actions",
"repository": "AdrienEtienne/actions-interactor",
"author": "AdrienEtienne <a.etienne92@gmail.com>",
Expand Down Expand Up @@ -43,6 +43,7 @@
"eslint-config-airbnb-base": "^10.0.1",
"eslint-plugin-import": "^2.2.0",
"istanbul": "^1.1.0-alpha.1",
"jsdoc": "^3.4.3",
"mocha": "^3.1.2",
"rollup": "^0.36.3",
"rollup-plugin-babel": "^2.6.1",
Expand All @@ -55,6 +56,7 @@
"test:cover": "babel-node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha",
"coveralls": "cat ./coverage/lcov.info | coveralls",
"build": "node tools/build",
"prepublish": "npm run build"
"prepublish": "npm run build",
"doc": "./node_modules/.bin/jsdoc -c ./conf.json"
}
}
24 changes: 23 additions & 1 deletion src/Interactor/Interactor.js
Expand Up @@ -3,6 +3,14 @@ import ActionInput from '../action/ActionInput';
import ActionCombo from '../action/ActionCombo';
import { ACTION_BASE, ACTION_COMBO, ACTION_INPUT } from '../action/ACTION_TYPE';

/**
* Manage actions to interact with
*
* @class Interactor
* @property {string} name Name
* @property {string} description Description
* @property {Array.<Action>} actions Actions
*/
class Interactor {
constructor(name = '', description = '') {
this.name = name;
Expand All @@ -11,6 +19,13 @@ class Interactor {
this.actions = [];
}

/**
* Test if actions are well filled
*
* @returns {boolean}
*
* @memberOf Interactor
*/
isValid() {
let result = true;

Expand All @@ -28,6 +43,13 @@ class Interactor {
return result;
}

/**
* Add an action to interactor
*
* @param {object} obj
*
* @memberOf Interactor
*/
addAction(obj = {}) {
switch (obj.type) {
case ACTION_BASE:
Expand All @@ -38,7 +60,7 @@ class Interactor {
case ACTION_INPUT:
this
.actions
.push(new ActionInput(obj.name, obj.description, obj.required, obj.defaultValue));
.push(new ActionInput(obj.name, obj.description, obj.required, obj.value));
return;

case ACTION_COMBO:
Expand Down
17 changes: 17 additions & 0 deletions src/action/ACTION_TYPE.js
@@ -1,3 +1,20 @@
export const ACTION_BASE = 'ACTION_BASE';
export const ACTION_INPUT = 'ACTION_INPUT';
export const ACTION_COMBO = 'ACTION_COMBO';

/**
* Enum Action types.
* @readonly
* @name ACTION_TYPE
* @enum {string}
*/
const ACTION_TYPE = {
/** Action base */
ACTION_BASE: 'ACTION_BASE',
/** Action input */
ACTION_INPUT: 'ACTION_INPUT',
/** Action combo */
ACTION_COMBO: 'ACTION_COMBO',
};

export default ACTION_TYPE;
25 changes: 24 additions & 1 deletion src/action/Action.js
@@ -1,16 +1,39 @@
import { ACTION_BASE } from './ACTION_TYPE';

export default class Action {
/**
* Action to interact with
*
* @property {string} name Name
* @property {string} description Description
* @property {ACTION_TYPE} type Type
*/
class Action {
/**
* Creates an instance of Action.
* @param {string} [name=''] Name
* @param {string} [description=''] Description
*
* @memberOf Action
*/
constructor(name = '', description = '') {
this.name = name;
this.description = description;
this.type = ACTION_BASE;
}

/**
* Test if action is valid
*
* @returns {boolean}
*
* @memberOf Action
*/
isValid() {
if (this.name) {
return true;
}
return false;
}
}

export default Action;
36 changes: 35 additions & 1 deletion src/action/ActionCombo.js
@@ -1,7 +1,24 @@
import Action from './Action';
import { ACTION_COMBO } from './ACTION_TYPE';

export default class ActionCombo extends Action {
/**
* Action Combo
*
* @extends {Action}
* @property {boolean} [required=false] Required
* @property {string} [value=''] Value
* @property {Array} choices Choices
*/
class ActionCombo extends Action {
/**
* Creates an instance of ActionCombo.
* @param {string} name Name
* @param {string} description Description
* @param {string} required Required
* @param {string} choices Choices
*
* @memberOf ActionCombo
*/
constructor(name, description, required, choices) {
super(name, description);
this.required = required;
Expand All @@ -18,13 +35,28 @@ export default class ActionCombo extends Action {
});
}

/**
* Test if valid
*
* @returns {boolean}
*
* @memberOf ActionCombo
*/
isValid() {
if (this.required && !this.value) {
return false;
}
return true;
}

/**
* Set choice
*
* @param {object} choice
* @returns {boolean}
*
* @memberOf ActionCombo
*/
setValue(choice = {}) {
let result = false;
this.choices.forEach((item) => {
Expand All @@ -38,3 +70,5 @@ export default class ActionCombo extends Action {
return result;
}
}

export default ActionCombo;
43 changes: 39 additions & 4 deletions src/action/ActionInput.js
@@ -1,22 +1,57 @@
import Action from './Action';
import { ACTION_INPUT } from './ACTION_TYPE';

export default class ActionInput extends Action {
constructor(name, description, required = false, defaultValue = '') {
/**
* Action which take an input
*
* @extends {Action}
* @property {boolean} [required=false] Required
* @property {string} [value=''] Value
* @property {string} [defaultValue=''] DefaultValue
* @deprecated Property defaultValue
*/
class ActionInput extends Action {
/**
* Creates an instance of ActionInput.
* @param {string} name
* @param {string} description
* @param {boolean} [required=false]
* @param {string} [value='']
*
* @memberOf ActionInput
*/
constructor(name, description, required = false, value = '') {
super(name, description);
this.type = ACTION_INPUT;
this.required = required;
this.defaultValue = defaultValue;
this.value = defaultValue;
this.defaultValue = value;
this.value = value;
}

/**
* Set value
*
* @param {string} value
* @returns {boolean}
*
* @memberOf ActionInput
*/
setValue(value) {
this.value = value;
return true;
}

/**
* Test if valid
*
* @returns {boolean}
*
* @memberOf ActionInput
*/
isValid() {
if (this.required && !this.value) return false;
return true;
}
}

export default ActionInput;

0 comments on commit a7671e4

Please sign in to comment.