browser-sync-spa
Advanced tools
Comparing version 1.0.0 to 1.0.1
(function (bs) { | ||
var EVENT_NAME = "history:change"; | ||
var sockets = bs.socket; | ||
@@ -17,6 +19,6 @@ | ||
window.onpopstate = history.onpushstate = function (out, args) { | ||
sockets.emit("history:change", {path: args[2]}); | ||
sockets.emit(EVENT_NAME, {path: args[2]}); | ||
} | ||
sockets.on("history:change", function (data) { | ||
sockets.on(EVENT_NAME, function (data) { | ||
@@ -46,9 +48,19 @@ var pathname = getLocation(data.path).pathname; | ||
function syncAngularLocation (pathname) { | ||
var $injector = angular.element(document.body).injector(); | ||
var $location = $injector.get('$location'); | ||
var $rootScope = $injector.get('$rootScope'); | ||
var elem; | ||
if (document.querySelector) { | ||
if (pathname !== $location.path()) { | ||
$location.path(pathname); | ||
$rootScope.$digest(); | ||
elem = document.querySelector('%SELECTOR%'); | ||
if (!elem) { | ||
return; | ||
} | ||
var $injector = angular.element(elem).injector(); | ||
var $location = $injector.get('$location'); | ||
var $rootScope = $injector.get('$rootScope'); | ||
if (pathname !== $location.path()) { | ||
$location.path(pathname); | ||
$rootScope.$digest(); | ||
} | ||
} | ||
@@ -55,0 +67,0 @@ } |
23
index.js
var historyApiFallback = require("connect-history-api-fallback"); | ||
var merger = require("opt-merger"); | ||
@@ -7,3 +8,6 @@ const PLUGIN_NAME = "BrowserSync SPA"; | ||
module.exports = { | ||
/** | ||
* Plugin interface for BrowserSync | ||
*/ | ||
var plugin = { | ||
"plugin:name": PLUGIN_NAME, | ||
@@ -15,3 +19,3 @@ "plugin": function (opts, instance) { | ||
"hooks": { | ||
"client:js": require("fs").readFileSync(__dirname + CLIENT_JS, "utf-8"), | ||
"client:js": "", | ||
"client:events": function () { | ||
@@ -25,1 +29,16 @@ return HISTORY_CHANGE_EVENT; | ||
} | ||
const defaults = { | ||
selector: "[ng-app]" | ||
}; | ||
/** | ||
* Allow run-time modifications to the client-side script | ||
* @param opts | ||
*/ | ||
module.exports = function (opts) { | ||
var config = merger.set({simple: true}).merge(defaults, opts); | ||
var clientJs = require("fs").readFileSync(__dirname + CLIENT_JS, "utf-8"); | ||
plugin.hooks["client:js"] = clientJs.replace("%SELECTOR%", config.selector); | ||
return plugin; | ||
} |
{ | ||
"name": "browser-sync-spa", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Single Page App support for BrowserSync", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha --recursive test/integration" | ||
}, | ||
@@ -24,3 +24,3 @@ "repository": { | ||
"devDependencies": { | ||
"browser-sync": "^1.6.5", | ||
"browser-sync": "^1.7.0", | ||
"chai": "^1.10.0", | ||
@@ -31,4 +31,5 @@ "mocha": "^2.0.1", | ||
"dependencies": { | ||
"connect-history-api-fallback": "0.0.5" | ||
"connect-history-api-fallback": "0.0.5", | ||
"opt-merger": "^1.1.0" | ||
} | ||
} |
13
test.js
var browserSync = require("browser-sync"); | ||
var spa = require("./index"); | ||
browserSync.use(require("./index")); | ||
browserSync.use(spa({ | ||
selector: "[ng-app]" | ||
})); | ||
browserSync({ | ||
open: false, | ||
server: { | ||
baseDir: "setups/backbone", | ||
files: "setups/angular/*" | ||
baseDir: "setups/angular" | ||
}, | ||
ghostMode: { | ||
clicks: false | ||
} | ||
files: "setups/angular/*" | ||
}); |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
0
0
49
1
1
5285
2
6
103
+ Addedopt-merger@^1.1.0
+ Addedlodash@3.10.1(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedopt-merger@1.1.1(transitive)