Skip to content

Commit

Permalink
review: es6ify lib/index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
mklabs committed Aug 17, 2016
1 parent 20a49a8 commit b83382d
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
var Server = require('./server');
var Client = require('./client');
var debug = require('debug')('tinylr');
import Server from './server';
import Client from './client';

const debug = require('debug')('tinylr');

// Need to keep track of LR servers when notifying
var servers = [];
const servers = [];

module.exports = tinylr;
export default tinylr;

// Expose Server / Client objects
tinylr.Server = Server;
Expand All @@ -17,14 +18,14 @@ tinylr.changed = changed;

// Main entry point
function tinylr (opts) {
var srv = new Server(opts);
const srv = new Server(opts);
servers.push(srv);
return srv;
}

// A facade to Server#handle
function middleware (opts) {
var srv = new Server(opts);
const srv = new Server(opts);
servers.push(srv);
return function tinylr (req, res, next) {
srv.handler(req, res, next);
Expand All @@ -33,12 +34,12 @@ function middleware (opts) {

// Changed helper, helps with notifying the server of a file change
function changed (done) {
var files = [].slice.call(arguments);
const files = [].slice.call(arguments);
if (files[files.length - 1] === 'function') done = files.pop();
done = typeof done === 'function' ? done : function () {};
done = typeof done === 'function' ? done : () => {};
debug('Notifying %d servers - Files: ', servers.length, files);
servers.forEach(function (srv) {
var params = { params: { files: files } };
servers.forEach(srv => {
const params = { params: { files: files } };
srv && srv.changed(params);
});
done();
Expand Down

0 comments on commit b83382d

Please sign in to comment.