Skip to content

Commit

Permalink
Adds AbstractPlugin class
Browse files Browse the repository at this point in the history
  • Loading branch information
tsov committed Jan 14, 2018
1 parent 5fceb1e commit 8410b5b
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 24 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
rules: {
'import/no-unresolved': 'off',
'import/no-extraneous-dependencies': 'off',
'class-methods-use-this': 'off',
},
globals: {
jest: false,
Expand Down
12 changes: 4 additions & 8 deletions src/Draggable/Plugins/Accessibility/Accessibility.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import AbstractPlugin from 'shared/AbstractPlugin';

const ARIA_GRABBED = 'aria-grabbed';
const ARIA_DROPEFFECT = 'aria-dropeffect';
const TABINDEX = 'tabindex';
Expand All @@ -7,21 +9,15 @@ const TABINDEX = 'tabindex';
* @class Accessibility
* @module Accessibility
*/
export default class Accessibility {
export default class Accessibility extends AbstractPlugin {

/**
* Accessibility constructor.
* @constructs Accessibility
* @param {Draggable} draggable - Draggable instance
*/
constructor(draggable) {

/**
* Draggable instance
* @property draggable
* @type {Draggable}
*/
this.draggable = draggable;
super(draggable);

this._onInit = this._onInit.bind(this);
this._onDestroy = this._onDestroy.bind(this);
Expand Down
11 changes: 3 additions & 8 deletions src/Draggable/Plugins/AutoScroll/AutoScroll.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import AbstractPlugin from 'shared/AbstractPlugin';
import {closest} from 'shared/utils';

export const onDragStart = Symbol('onDragStart');
Expand All @@ -22,21 +23,15 @@ export const defaultOptions = {
* @class AutoScroll
* @module AutoScroll
*/
export default class AutoScroll {
export default class AutoScroll extends AbstractPlugin {

/**
* AutoScroll constructor.
* @constructs AutoScroll
* @param {Draggable} draggable - Draggable instance
*/
constructor(draggable) {

/**
* Draggable instance
* @property draggable
* @type {Draggable}
*/
this.draggable = draggable;
super(draggable);

/**
* AutoScroll options
Expand Down
7 changes: 5 additions & 2 deletions src/Draggable/Plugins/Mirror/Mirror.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import AbstractPlugin from 'shared/AbstractPlugin';

export const defaultOptions = {
constrainDimensions: false,
xAxis: true,
yAxis: true,
};

export default class Mirror {
export default class Mirror extends AbstractPlugin {
constructor(draggable) {
this.draggable = draggable;
super(draggable);

this.options = {
...defaultOptions,
...this.getOptions(),
Expand Down
5 changes: 3 additions & 2 deletions src/Plugins/Collidable/Collidable.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import AbstractPlugin from 'shared/AbstractPlugin';
import {closest} from 'shared/utils';

import {
CollidableInEvent,
CollidableOutEvent,
} from './CollidableEvent';

export default class Collidable {
export default class Collidable extends AbstractPlugin {
constructor(draggable) {
this.draggable = draggable;
super(draggable);

this._onDragMove = this._onDragMove.bind(this);
this._onDragStop = this._onDragStop.bind(this);
Expand Down
6 changes: 4 additions & 2 deletions src/Plugins/Snappable/Snappable.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import AbstractPlugin from 'shared/AbstractPlugin';

import {
SnapInEvent,
SnapOutEvent,
} from './SnappableEvent';

export default class Snappable {
export default class Snappable extends AbstractPlugin {
constructor(draggable) {
this.draggable = draggable;
super(draggable);

this._onDragStart = this._onDragStart.bind(this);
this._onDragStop = this._onDragStop.bind(this);
Expand Down
6 changes: 4 additions & 2 deletions src/Plugins/SwapAnimation/SwapAnimation.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import AbstractPlugin from 'shared/AbstractPlugin';

export const defaultOptions = {
duration: 150,
easingFunction: 'ease-in-out',
};

export default class SwapAnimation {
export default class SwapAnimation extends AbstractPlugin {
constructor(draggable) {
this.draggable = draggable;
super(draggable);

this.options = {
...defaultOptions,
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AbstractEvent from 'shared/AbstractEvent';
import AbstractPlugin from 'shared/AbstractPlugin';

import * as Sensors from './Draggable/Sensors';
import * as Plugins from './Plugins';
Expand All @@ -10,6 +11,7 @@ import Sortable from './Sortable';

export {
AbstractEvent as BaseEvent,
AbstractPlugin as BasePlugin,
Sensors,
Plugins,

Expand Down
2 changes: 2 additions & 0 deletions src/index.legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'core-js/fn/object/assign';
import 'core-js/fn/array/includes';

import AbstractEvent from 'shared/AbstractEvent';
import AbstractPlugin from 'shared/AbstractPlugin';

import * as Sensors from './Draggable/Sensors';
import * as Plugins from './Plugins';
Expand All @@ -15,6 +16,7 @@ import Sortable from './Sortable';

export {
AbstractEvent as BaseEvent,
AbstractPlugin as BasePlugin,
Sensors,
Plugins,

Expand Down
39 changes: 39 additions & 0 deletions src/shared/AbstractPlugin/AbstractPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* All draggable plugins inherit from this class.
* @abstract
* @class AbstractPlugin
* @module AbstractPlugin
*/
export default class AbstractPlugin {

/**
* AbstractPlugin constructor.
* @constructs AbstractPlugin
* @param {Draggable} draggable - Draggable instance
*/
constructor(draggable) {

/**
* Draggable instance
* @property draggable
* @type {Draggable}
*/
this.draggable = draggable;
}

/**
* Override to add listeners
* @abstract
*/
attach() {
throw new Error('Not Implemented');
}

/**
* Override to remove listeners
* @abstract
*/
detach() {
throw new Error('Not Implemented');
}
}
14 changes: 14 additions & 0 deletions src/shared/AbstractPlugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Abstract plugin

This is the base class for all draggable plugins.

### API

**`new AbstractPlugin(draggable: Draggable): AbstractPlugin`**
Creates an `AbstractPlugin` instance.

**`abstractEvent.attach(): void`**
Attaches listeners for plugin.

**`abstractEvent.detach(): void`**
Detaches listeners for plugin.
3 changes: 3 additions & 0 deletions src/shared/AbstractPlugin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import AbstractPlugin from './AbstractPlugin';

export default AbstractPlugin;

0 comments on commit 8410b5b

Please sign in to comment.