Skip to content

Commit ed51a31

Browse files
committed
props example
1 parent d346e3b commit ed51a31

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

README.md

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Below is a list of these methods and properties. Then you can see [an example im
2525
- [`_afterInitialize()`](#_afterinitialize)
2626
- [`initialize()`](#initialize)
2727
- [`defaults`](#defaults)
28+
- [`defaultSettings`](#defaultsettings)
29+
- [`defaultProps`](#defaultprops)
2830

2931

3032
### `constructor()`
@@ -77,7 +79,8 @@ A getter that returns an object with default options, settings, or configuration
7779
_`public`_
7880
_**`since v3.0.0`**_
7981

80-
A getter that returns an object with predefined props, which can be represented as a list of flags (aka properties API) that affects your settings, etc.
82+
A getter that returns an object with predefined props.
83+
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.
8184

8285
---
8386

@@ -99,19 +102,27 @@ export class SomeJqueryPluginAbstract extends WebPluginInterface {
99102
/**
100103
* @param {jQuery} $container
101104
* @param {Object} [customSettings={}]
105+
* @param {Object} [customProps={}]
102106
*/
103-
constructor ($container, customSettings = {}) {
107+
constructor ($container, customSettings = {}, customProps = {}) {
104108
super();
105109
this.$container = $container;
106110
this.customSettings = customSettings;
107111
this.settings = {};
112+
this.props = {};
108113
this.readyCssClass = 'is-ready';
109114
this.initializedCssClass = 'is-initialized';
110115
}
111116

112117
/** @protected */
113118
_setup () {
114-
this.settings = $.extends({}, this.defaults, this.customSettings);
119+
this.props = $.extends({}, this.defaultProps, this.customProps);
120+
this.settings = $.extends({}, this.defaultSettings, this.customSettings);
121+
122+
// props example
123+
if (this.props.stopAutoPlayIfOutView) {
124+
this.settings.autoplay = this.detectIfInView();
125+
}
115126
}
116127

117128
/** @protected */
@@ -122,6 +133,11 @@ export class SomeJqueryPluginAbstract extends WebPluginInterface {
122133
/** @protected */
123134
_afterInitialize () {
124135
this.$container.addClass(this.initializedCssClass);
136+
137+
// props example
138+
if (this.props.stopAutoPlayIfOutView) {
139+
this.autoplayInViewObserve()
140+
}
125141
}
126142

127143
/** @public */
@@ -136,12 +152,31 @@ export class SomeJqueryPluginAbstract extends WebPluginInterface {
136152
* @public
137153
* @returns Object
138154
*/
139-
get defaults () {
155+
get defaultSettings () {
140156
return {
141157
// an example of some options of your plugin
142-
autoplay: false,
158+
autoplay: true,
143159
speed: 500
144160
}
145161
}
162+
163+
get defaultProps () {
164+
return {
165+
// an example of options that is native for your plugin
166+
stopAutoPlayIfOutView: true
167+
}
168+
}
169+
170+
// ------------------------------
171+
// Custom extend implemented interface
172+
// ------------------------------
173+
174+
detectIfInView () {
175+
// your code
176+
}
177+
178+
autoplayInViewObserve () {
179+
// your code
180+
}
146181
}
147182
```

0 commit comments

Comments
 (0)