Skip to content

Commit

Permalink
Working version
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-steele-idem committed Dec 11, 2014
1 parent 7dc58e6 commit c4cbed1
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 1 deletion.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

node_modules
npm-debug.log
*.sublime-workspace
*.sublime-project
36 changes: 36 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"predef": [
"require"
],

"strict": false,
"globalstrict": true,
"node" : true,
"es5" : false,
"browser" : true,
"boss" : false,
"curly": false,
"debug": false,
"devel": false,
"eqeqeq": true,
"evil": true,
"forin": false,
"immed": true,
"laxbreak": false,
"newcap": true,
"noarg": true,
"noempty": false,
"nonew": true,
"nomen": false,
"onevar": false,
"plusplus": false,
"regexp": false,
"undef": true,
"sub": false,
"white": false,
"eqeqeq": false,
"latedef": true,
"unused": "vars",
"eqnull": true,
"sub": true
}
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
browser-refresh-client
======================

Small module to interface with the parent browser-refresh process to control reloading
Small module that allows the current child process launched by [browser-refresh](https://github.com/patrick-steele-idem/browser-refresh) to control the parent `browser-refresh` process. If the process was not launched by the `browser-refresh` launcher then operations will be a no-op.

# Installation

```bash
npm install browser-refresh-client --save
```

# Usage

## Check if the current process was launched using `browser-refresh`

```javascript
require('browser-refresh-client').isBrowserRefreshEnabled();
```


## Enable special reloading of files

```javascript
require('browser-refresh-client')
.enableSpecialReload('*.foo *.bar')
.onFileModified(function(path) {
// Handle the modification of either a *.foo file or
// a *.bar file...
});
```
41 changes: 41 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var EventEmitter = require('events').EventEmitter;

function isBrowserRefreshEnabled() {
return process.env.BROWSER_REFRESH_URL != null;
}

var nextId = 0;

exports.isBrowserRefreshEnabled = isBrowserRefreshEnabled;

exports.enableSpecialReload = function(patterns) {

if (isBrowserRefreshEnabled()) {
var events = new EventEmitter();

var modifiedEvent = 'browser-refresh-client.fileModified' + (nextId++);

process.send({
type: 'browser-refresh.specialReload',
patterns: patterns,
modifiedEvent: modifiedEvent
});

process.on('message', function(m) {
if (typeof m === 'object' && m.type === modifiedEvent) {
var path = m.path;
events.emit('fileModified', path);
}
});

return {
onFileModified: function(callback) {
events.on('fileModified', callback);
}
};
} else {
return {
onFileModified: function() { /* no-op */ }
};
}
};
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "browser-refresh-client",
"description": "Small module to interface with the parent browser-refresh process to control reloading of files.",
"main": "lib/index",
"scripts": {},
"repository": {
"type": "git",
"url": "https://github.com/patrick-steele-idem/browser-refresh-client.git"
},
"keywords": [
"browser",
"refresh",
"live",
"coding",
"reload",
"watch"
],
"author": "Patrick Steele-Idem <pnidem@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/patrick-steele-idem/browser-refresh-client/issues"
},
"homepage": "https://github.com/patrick-steele-idem/browser-refresh-client",
"dependencies": {
},
"version": "1.0.0"
}

0 comments on commit c4cbed1

Please sign in to comment.