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
Copy file name to clipboardExpand all lines: README.md
+31Lines changed: 31 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -191,6 +191,37 @@ class App.Element.MainMenu
191
191
return this
192
192
```
193
193
194
+
We can now add all the logic for the main menu in a separate class and call it on every page like so:
195
+
196
+
```
197
+
# app/assets/javascripts/base.js.coffee
198
+
window.App ||= {}
199
+
class App.Base
200
+
201
+
constructor: ->
202
+
App.mainMenu = new App.Element.MainMenu()
203
+
return this
204
+
```
205
+
206
+
207
+
#### Element Inheritance
208
+
209
+
Inheritance is another key tool for reusability. Let's say our ```Element.MainMenu``` opens and closes in the same way as the ```Utility.Modal```. Well then MainMenu should just extend Modal, this can be accomplished from the generator:
class App.Element.MainMenu extends App.Utility.Modal
219
+
220
+
constructor: ->
221
+
return this
222
+
````
223
+
224
+
Inheritance from the generator can only come from a Utility class. Any custom class you wish to extend should be created as a Utility. The installer adds the line ```//= require_tree ./utilities``` before loading tree to handle this. If you have a utility that extends a utility, you should make sure the extended utility is loaded first by explicitly requiring it before the utilities tree.
0 commit comments