Refactor privates to have the _ prefix

This commit is contained in:
Ciro Nunes 2015-09-30 08:46:36 -03:00
parent 1539bba290
commit 7c4108f48a
4 changed files with 19 additions and 19 deletions

View File

@ -7,15 +7,15 @@ class ClipboardAction {
* @param {Object} options
*/
constructor(options) {
this.resolveOptions(options);
this.initSelection();
this._resolveOptions(options);
this._initSelection();
}
/**
* Defines base properties passed from constructor.
* @param {Object} options
*/
resolveOptions(options = {}) {
_resolveOptions(options = {}) {
this.action = options.action;
this.emitter = options.emitter;
this.target = options.target;
@ -29,7 +29,7 @@ class ClipboardAction {
* Decides which selection strategy is going to be applied based
* on the existence of `text` and `target` properties.
*/
initSelection() {
_initSelection() {
if (this.text && this.target) {
throw new Error('Multiple attributes declared, use either "target" or "text"');
}
@ -37,7 +37,7 @@ class ClipboardAction {
this.selectFake();
}
else if (this.target) {
this.selectTarget();
this._selectTarget();
}
else {
throw new Error('Missing required attributes, use either "target" or "text"');
@ -63,7 +63,7 @@ class ClipboardAction {
document.body.appendChild(this.fakeElem);
this.fakeElem.select();
this.copyText();
this._copyText();
}
/**
@ -85,7 +85,7 @@ class ClipboardAction {
/**
* Selects the content from element passed on `target` property.
*/
selectTarget() {
_selectTarget() {
if (this.target.nodeName === 'INPUT' || this.target.nodeName === 'TEXTAREA') {
this.target.select();
this.selectedText = this.target.value;
@ -99,13 +99,13 @@ class ClipboardAction {
this.selectedText = selection.toString();
}
this.copyText();
this._copyText();
}
/**
* Executes the copy operation based on the current selection.
*/
copyText() {
_copyText() {
let succeeded;
try {

View File

@ -16,8 +16,8 @@ class Clipboard extends Emitter {
constructor(selector, options) {
super();
this.resolveOptions(options);
this.delegateClick(selector);
this._resolveOptions(options);
this._delegateClick(selector);
}
/**
@ -25,17 +25,17 @@ class Clipboard extends Emitter {
* or custom functions that were passed in the constructor.
* @param {Object} options
*/
resolveOptions(options = {}) {
_resolveOptions(options = {}) {
this.action = (typeof options.action === 'function') ? options.action : this.setAction;
this.target = (typeof options.target === 'function') ? options.target : this.setTarget;
this.text = (typeof options.text === 'function') ? options.text : this.setText;
}
/**
* Delegates a click event on the passed selector.
* Delegates a click event to the passed selector.
* @param {String} selector
*/
delegateClick(selector) {
_delegateClick(selector) {
Delegate.bind(document.body, selector, 'click', (e) => this.initialize(e));
}

View File

@ -19,7 +19,7 @@ describe('ClipboardAction', () => {
document.body.innerHTML = '';
});
describe('#resolveOptions', () => {
describe('_resolveOptions', () => {
it('should set base properties', () => {
let clip = new ClipboardAction({
emitter: new Emitter(),
@ -35,7 +35,7 @@ describe('ClipboardAction', () => {
});
});
describe('#initSelection', () => {
describe('_initSelection', () => {
it('should throw an error since both "text" and "target" were passed', done => {
try {
new ClipboardAction({
@ -113,7 +113,7 @@ describe('ClipboardAction', () => {
});
});
describe('#selectTarget', () => {
describe('_selectTarget', () => {
it('should select text from editable element', () => {
let clip = new ClipboardAction({
emitter: new Emitter(),

View File

@ -18,7 +18,7 @@ describe('Clipboard', () => {
document.body.innerHTML = '';
});
describe('#resolveOptions', function() {
describe('_resolveOptions', function() {
before(() => {
global.fn = function() {};
});
@ -48,7 +48,7 @@ describe('Clipboard', () => {
});
});
describe('#delegateClick', function() {
describe('_delegateClick', function() {
before(() => {
global.spy = sinon.spy(Delegate, 'bind');
});