@adoratorio/hades
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -34,2 +34,3 @@ import Aion from '@adoratorio/aion'; | ||
export interface HadesPlugin { | ||
id?: string; | ||
name: string; | ||
@@ -36,0 +37,0 @@ register?: Function; |
@@ -25,2 +25,3 @@ import { DIRECTION, HadesOptions, Vec2, Easing, HadesPlugin } from "./declarations"; | ||
private plugins; | ||
private internalId; | ||
amount: Vec2; | ||
@@ -33,3 +34,5 @@ velocity: Vec2; | ||
scrollTo(position: Partial<Vec2>, duration: number, prevent?: boolean): void; | ||
registerPlugin(plugin: HadesPlugin | Array<HadesPlugin>): Array<HadesPlugin>; | ||
registerPlugin(plugin: HadesPlugin, id?: string): string; | ||
unregisterPlugin(id: string): boolean; | ||
registerPlugins(plugins: Array<HadesPlugin>, ids: Array<string>): Array<string>; | ||
getPlugin(name: string): HadesPlugin | undefined; | ||
@@ -50,3 +53,4 @@ play(): void; | ||
set internalTemp(values: Vec2); | ||
private register; | ||
} | ||
export default Hades; |
@@ -32,2 +32,3 @@ "use strict"; | ||
this.plugins = []; | ||
this.internalId = 0; | ||
this.amount = { x: 0, y: 0 }; | ||
@@ -193,17 +194,30 @@ this.velocity = { x: 0, y: 0 }; | ||
}; | ||
Hades.prototype.registerPlugin = function (plugin) { | ||
var _this = this; | ||
var register = function (plugin) { | ||
if (typeof plugin.register === 'function') | ||
plugin.register(_this); | ||
_this.plugins.push(plugin); | ||
}; | ||
if (Array.isArray(plugin)) { | ||
plugin.forEach(function (plugin) { register(plugin); }); | ||
Hades.prototype.registerPlugin = function (plugin, id) { | ||
var i = null; | ||
if (typeof id === 'undefined') { | ||
i = "hades-plugin-".concat(this.internalId); | ||
this.internalId += 1; | ||
} | ||
else { | ||
register(plugin); | ||
i = id; | ||
} | ||
return this.plugins; | ||
this.register(plugin, i); | ||
return i; | ||
}; | ||
Hades.prototype.unregisterPlugin = function (id) { | ||
var foundIndex = this.plugins.findIndex(function (p) { return p.id === id; }); | ||
var found = this.plugins[foundIndex]; | ||
if (typeof (found === null || found === void 0 ? void 0 : found.destroy) === 'function') | ||
found.destroy(); | ||
this.plugins.splice(foundIndex, 1); | ||
return foundIndex === -1 ? false : true; | ||
}; | ||
Hades.prototype.registerPlugins = function (plugins, ids) { | ||
var _this = this; | ||
var is = []; | ||
plugins.forEach(function (plugin, index) { | ||
is.push(_this.registerPlugin(plugin, ids[index])); | ||
}); | ||
return is; | ||
}; | ||
Hades.prototype.getPlugin = function (name) { | ||
@@ -302,2 +316,8 @@ return this.plugins.find(function (plugin) { return plugin.name === name; }); | ||
}); | ||
Hades.prototype.register = function (plugin, id) { | ||
if (typeof plugin.register === 'function') | ||
plugin.register(this); | ||
plugin.id = id; | ||
this.plugins.push(plugin); | ||
}; | ||
Hades.EASING = easing_1.default; | ||
@@ -304,0 +324,0 @@ Hades.DIRECTION = declarations_1.DIRECTION; |
{ | ||
"name": "@adoratorio/hades", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "A smooth scrollbar based on Hermes, scroll down 'till hell", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -64,5 +64,5 @@ # Hades | ||
Register a plugin inside the current `Hades` instance. Return an array with all the plugins currently registered | ||
Register a plugin inside the current `Hades` instance. Return a string with the registration id, useful for unregister | ||
```typescript | ||
hades.registerPlugin(plugin : HadesPlugin) : Array<HadesPlugin> | ||
hades.registerPlugin(plugin : HadesPlugin) : string | ||
``` | ||
@@ -76,2 +76,28 @@ | ||
### registerPlugins() | ||
Register multiple plugins inside the current `Hades` instance. Return an array of strings with the registration ids in positional corrispondence with the provided plugins array | ||
```typescript | ||
hades.registerPlugins(plugin : Array<HadesPlugin>) : Array<string> | ||
``` | ||
**Parameters** | ||
| parameter | required | description | | ||
|:---|:---:|:---| | ||
| plugin | `HadesPlugin` | The instance of the plugin to register | | ||
### unregisterPlugin() | ||
Remove a plugin from the current `Hades` instance using the registration id of the plugin. Return `true` if the plugin was found and unregistered | ||
```typescript | ||
hades.unregisterPlugin(id : string) : boolean | ||
``` | ||
**Parameters** | ||
| parameter | required | description | | ||
|:---|:---:|:---| | ||
| plugin | `HadesPlugin` | The instance of the plugin to register | | ||
### getPlugin() | ||
@@ -78,0 +104,0 @@ |
59458
1239
271