Skip to content

Commit

Permalink
improve callback api interface
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickkunka committed May 8, 2018
1 parent b7f8737 commit 3d25cf8
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bundle/easydropdown.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bundle/easydropdown.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion demos/easydropdown.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion demos/easydropdown.js.map

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions src/Easydropdown/Easydropdown.test.ts
Expand Up @@ -75,6 +75,20 @@ describe('Easydropdown', () => {
assert.isTrue(onCloseSpy.called);
});

it('does not invoke consumer callbacks if not provided', () => {
const select = createSelect();

const edd = new Easydropdown(select, {});

edd.actions.selectOption(1);

edd.open();

edd.actions.close();

assert.isTrue(true);
});

describe('.open()', () => {
it('programmatically opens the select', () => {
const select = createSelect();
Expand Down
9 changes: 4 additions & 5 deletions src/Easydropdown/Easydropdown.ts
Expand Up @@ -3,6 +3,7 @@ import merge from 'helpful-merge';
import Config from '../Config/Config';
import ICallback from '../Config/Interfaces/ICallback';
import IConfig from '../Config/Interfaces/IConfig';
import ISelectCallback from '../Config/Interfaces/ISelectCallback';
import bindEvents from '../Events/bindEvents';
import EventBinding from '../Events/EventBinding';
import Dom from '../Renderer/Dom';
Expand Down Expand Up @@ -112,7 +113,6 @@ class Easydropdown {
const {callbacks} = this.config;

let cb: ICallback;
let arg: any;

this.renderer.update(state, key);

Expand All @@ -124,15 +124,14 @@ class Easydropdown {
cb = callbacks.onClose;
}

if (typeof cb === 'function') cb();

break;
case 'selectedIndex':
cb = callbacks.onSelect;
arg = state.value;

break;
if (typeof cb === 'function') (cb as ISelectCallback)(state.value);
}

if (typeof cb === 'function') cb(arg);
}
}

Expand Down

0 comments on commit 3d25cf8

Please sign in to comment.