Skip to content

Commit cbc95be

Browse files
Merge pull request #6 from dutchenkoOleg/master
3.0.0
2 parents 5b11db3 + 640e4bb commit cbc95be

File tree

4 files changed

+104
-28
lines changed

4 files changed

+104
-28
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.idea
22
bash.exe.stackdump
3+
.vscode
4+
.vagrant
35

46
# Logs
57
logs

README.md

Lines changed: 86 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ Below is a list of these methods and properties. Then you can see [an example im
2020
---
2121

2222
- [`constructor()`](#constructor)
23+
- [_~~defaults~~_](#defaults)
24+
- [`defaultSettings`](#defaultsettings)
25+
- [`defaultProps`](#defaultprops)
2326
- [`_setup()`](#_setup)
2427
- [`_beforeInitialize()`](#_beforeinitialize)
2528
- [`_afterInitialize()`](#_afterinitialize)
2629
- [`initialize()`](#initialize)
27-
- [`defaults`](#defaults)
2830

2931

3032
### `constructor()`
@@ -33,6 +35,25 @@ Here we describe the future instances.:
3335
- get data from arguments
3436
- declare instance properties
3537

38+
### `defaults`
39+
40+
> since v3.0.0 property renamed to `defaultSettings`
41+
42+
### `defaultSettings`
43+
44+
_`public`_
45+
_**`since v3.0.0`**_
46+
47+
A getter that returns an object with default options, settings, or configuration for your plugin.
48+
49+
### `defaultProps`
50+
51+
_`public`_
52+
_**`since v3.0.0`**_
53+
54+
A getter that returns an object with predefined props.
55+
Most often this is a list of options that are not included in the list of certain options of your plugin. But you need them for individual processing your options, settings, data, etc.
56+
3657

3758
### `_setup()`
3859

@@ -61,12 +82,6 @@ _`public`_
6182

6283
Directly launch your plugin.
6384

64-
### `defaults`
65-
66-
_`public`_
67-
68-
A getter that returns an object with default options, settings, or configuration for your plugin.
69-
7085
---
7186

7287
## Usage example
@@ -87,49 +102,97 @@ export class SomeJqueryPluginAbstract extends WebPluginInterface {
87102
/**
88103
* @param {jQuery} $container
89104
* @param {Object} [customSettings={}]
105+
* @param {Object} [customProps={}]
90106
*/
91-
constructor ($container, customSettings = {}) {
107+
constructor ($container, customSettings = {}, customProps = {}) {
92108
super();
93109
this.$container = $container;
94110
this.customSettings = customSettings;
95111
this.settings = {};
112+
this.props = {};
96113
this.readyCssClass = 'is-ready';
97114
this.initializedCssClass = 'is-initialized';
98115
}
116+
117+
/**
118+
* @type {Object}
119+
*/
120+
get defaultSettings () {
121+
return {
122+
// an example of some options of your plugin
123+
autoplay: true,
124+
speed: 500
125+
}
126+
}
99127

100-
/** @protected */
128+
/**
129+
* @type {Object}
130+
*/
131+
get defaultProps () {
132+
return {
133+
// an example of options that is native for your plugin
134+
stopAutoPlayIfOutView: true
135+
}
136+
}
137+
138+
/**
139+
* @protected
140+
*/
101141
_setup () {
102-
this.settings = $.extends({}, this.defaults, this.customSettings);
142+
this.props = $.extends({}, this.defaultProps, this.customProps);
143+
this.settings = $.extends({}, this.defaultSettings, this.customSettings);
144+
145+
// props example
146+
if (this.props.stopAutoPlayIfOutView) {
147+
this.settings.autoplay = this.detectIfInView;
148+
}
103149
}
104150

105-
/** @protected */
151+
/**
152+
* @protected
153+
*/
106154
_beforeInitialize () {
107155
this.$container.addClass(this.readyCssClass);
108156
}
109157

110-
/** @protected */
158+
/**
159+
* @protected
160+
*/
111161
_afterInitialize () {
112162
this.$container.addClass(this.initializedCssClass);
163+
164+
// props example
165+
if (this.props.stopAutoPlayIfOutView) {
166+
this._autoplayInViewObserve();
167+
}
113168
}
114169

115-
/** @public */
116170
initialize () {
117-
this._setup();
118-
this._beforeInitialize();
171+
this._setup();
172+
this._beforeInitialize();
173+
174+
// fire up
119175
this.$container.someJqueryPlugin(this.settings);
176+
120177
this._afterInitialize();
121178
}
179+
180+
// ------------------------------
181+
// Custom extend implemented interface
182+
// ------------------------------
183+
184+
/**
185+
* @type {boolean}
186+
*/
187+
get detectIfInView () {
188+
// your code
189+
}
122190

123191
/**
124-
* @public
125-
* @returns Object
192+
* @protected
126193
*/
127-
get defaults () {
128-
return {
129-
// an example of some options of your plugin
130-
autoplay: false,
131-
speed: 500
132-
}
194+
_autoplayInViewObserve () {
195+
// your code
133196
}
134197
}
135198
```

index.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/**
44
* @module WebPluginInterface
55
* @author OlegDutchenko <[email protected]>
6+
* @version 3.0.0
67
*/
78

89
/**
@@ -13,6 +14,20 @@ export class WebPluginInterface {
1314
// code
1415
}
1516

17+
/**
18+
* @type {Object}
19+
*/
20+
get defaultSettings () {
21+
return {};
22+
}
23+
24+
/**
25+
* @type {Object}
26+
*/
27+
get defaultProps () {
28+
return {};
29+
}
30+
1631
/**
1732
* @protected
1833
*/
@@ -37,8 +52,4 @@ export class WebPluginInterface {
3752
initialize () {
3853
// code
3954
}
40-
41-
get defaults () {
42-
return {};
43-
}
4455
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web-plugin-interface",
3-
"version": "2.0.2",
3+
"version": "3.0.0",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)