@yuheiy/page-dispatcher
v0.0.4
Published
Divide logic of JavaScript by your page.
Downloads
10
Readme
Page Dispatcher
Divide logic of JavaScript by your page.
Concept
Installation
$ npm install --save @yuheiy/page-dispatcher
Usage
'use strict';
var PageDispatcher = require('@yuheiy/page-dispatcher');
var dispatcher = new PageDispatcher();
dispatcher.on('common', function () {
// run on all pages
});
dispatcher.on('home', function (message) {
// run only on home
console.log(message);
});
window.run = dispatcher.run.bind(dispatcher);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Home - Site Name</title>
</head>
<body>
<h1>Home</h1>
<script src="bundle.js"></script>
<script>
run('common');
run('home', 'This is a home of this site.');
</script>
</body>
</html>