-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7dc58e6
commit c4cbed1
Showing
5 changed files
with
148 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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... | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ } | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |