Events: Allow for easier application extension with hook points.

How does it work?

Every time someone wants to extend the application, instead of modifying original `publishing.js` file, he or she can subscribe to given events, e.g.

Scenario: Table Of Contents extension

```
// resources/public/js/toc.js

events.subscribe('content:rendered', function () {
  // Prepend table of contents in edit mode on updates
});

events.subscribe('document:loaded', function () {
  // Prepend table of contents on initial load in edit view and preview
});
```

Now, having structured way to hook into app allows to keep the main codebase maintainable and pretty stable and extremely extensible at the same time.
This commit is contained in:
Maciej Smolinski
2016-07-19 19:03:20 +02:00
parent e902fc3a26
commit e25926619e
4 changed files with 75 additions and 0 deletions
+6
View File
@@ -12,5 +12,11 @@
%CONTENT%
</article>
%FOOTER%
<script src="/js/events.js"></script>
<script>
events.publish('document:loaded');
</script>
</body>
</html>