You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 30, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+40Lines changed: 40 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,7 @@ which is designed for easy-to-use implementation purpose in "oldschool" multipag
20
20
1.[Mounting plugins](#mounting-plugins)
21
21
1.[Configuring plugins](#configure-plugins)
22
22
1.[Global messages](#global-messages)
23
+
1.[Extending a Plugin (inheritance)](#extending-a-plugin-inheritance)
23
24
1.[Dynamic (un)mounting](#dynamic-unmounting)
24
25
1.[Best practices](#best-practices)
25
26
1.[Building your project](#building-your-project)
@@ -264,6 +265,45 @@ define(['Plugin', 'Window'], function (Plugin, Window) {
264
265
265
266
All the listeners which have been registered using bindSystemMessage will be destroyed automatically when the plugin instance is destroyed (unmounted).
266
267
268
+
### Extending a Plugin (inheritance)
269
+
270
+
Extending a plugin is still simple. Every plugin in the example extends the base plugin "Plugin".
271
+
To extend our own plugin we use an Alerter again as example:
272
+
273
+
```javascript
274
+
define(['Plugin', 'Window'], function (Plugin, Window) {
275
+
var Alerter =Plugin.extend({
276
+
execute:function () {
277
+
var me =this;
278
+
me.showMsg(me.$element.text());
279
+
},
280
+
showMsg:function (msg) {
281
+
var me =this;
282
+
Window.alert(msg);
283
+
}
284
+
});
285
+
return Alerter;
286
+
});
287
+
```
288
+
289
+
Now we implement a SpecialAlerter:
290
+
291
+
```javascript
292
+
define(['plugins/Alerter'], function (Alerter) {
293
+
var SpecialAlerter =Alerter.extend({
294
+
showMsg:function (msg) {
295
+
var me =this;
296
+
//calling base method
297
+
me.base('Special:'+ msg);
298
+
}
299
+
});
300
+
return SpecialAlerter;
301
+
});
302
+
```
303
+
We overwrite the showMsg function to prepend th 'Special' string to the message.
304
+
After that we calling the function from the base class.
305
+
306
+
267
307
### Dynamic (un)mounting
268
308
mntyjs uses a Mutation-Observer Shim, which allows you to dynamically add and remove elements which use plugins as well. The MutationObserver will notify mntyjs which will initialize / destroy all the plugins of the according elements.
0 commit comments