Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jsbin/jsbin
base: master
...
head fork: jsbin/jsbin
compare: fix/ping-processors
Checking mergeability… Don’t worry, you can still create the pull request.
  • 6 commits
  • 6 files changed
  • 0 commit comments
  • 2 contributors
Commits on Jul 16, 2014
@electricg electricg First commit a081945
@remy remy .then(resolve) - but still needs work d81027f
Commits on Jul 17, 2014
@remy remy Mocking up how to send processed with connections
The idea being: if there's a viewer, then send the processed CSS up to a /spike end point (that is then propergated to connected viewers through the spike).

Obviously! Needs careful testing...maybe even some *real* tests?!?!?!?!?!?!?!?!
817ebe1
@electricg electricg Fixed resolve call 36bf0e8
@electricg electricg Restore original lib/spike/index.js 5d7097f
@electricg electricg Still not working 100% d767c3f
View
6 lib/routes.js
@@ -514,6 +514,12 @@ module.exports = function (app) {
// If the above route fails then it's either a clone or a revision. Which
// the handler can check in the post body.
app.post('/:bin/:rev?/save', time('request.bin.update'), binHandler.createRevisionOrClone);
+ app.post('/:bin/:rev?/spike', binHandler.reload);
+ // function () {
+ // 1. if the key in the body is "valid"
+ // 2. then emit('spike-ping', req.body)
+ // spike.ping.bind(spike)
+ // });
app.post('/:bin/:rev?/reload', binHandler.reload);
// delete a bin
View
5 lib/spike/index.js
@@ -136,13 +136,12 @@ utils.process = function(data, settings) {
return data;
}
// Find this processor in the list of processors
- if (!processors[processorName]) {
- return newData;
+ if (!processors.support(processorName)) {
+ return data;
}
// And process!
var newData = _.clone(data);
newData.raw = data.content;
- newData.content = processors[processorName](data.content);
return newData;
};
View
2  public/js/chrome/infocard.js
@@ -118,6 +118,8 @@
function updateStats(event, _data) {
var data = _data ? JSON.parse(_data) : JSON.parse(event.data);
+ jsbin.state.connections = data.connections;
+
if (data.connections > 0 && viewers === 0) {
$template.addClass('viewers');
}
View
6 public/js/render/live.js
@@ -54,10 +54,14 @@ var deferCallable = function (newFn, trigger) {
function sendReload() {
if (saveChecksum) {
$.ajax({
- url: jsbin.getURL() + '/reload',
+ url: jsbin.getURL() + '/spike',
data: {
code: jsbin.state.code,
revision: jsbin.state.revision,
+ payload: {
+ event: 'css:processed',
+ data: ''
+ },
checksum: saveChecksum
},
type: 'post'
View
12 public/js/render/render.js
@@ -30,7 +30,17 @@ var getRenderedCode = function () {
function render(language) {
return new RSVP.Promise(function (resolve, reject) {
- editors[language].render().then(resolve, function (error) {
+ editors[language].render().then(function (data) {
+ if (jsbin.state.connections > 0) { //} && language === 'css' && editors[language].processor.id !== 'css') {
+ $.ajax({
+ method: 'post',
+ url: jsbin.getURL({ withRevision: true }) + '/spike',
+ data: { data: data },
+ language: editors[language].processor.id
+ });
+ }
+ resolve(data);
+ }, function (error) {
console.warn(editors[language].processor.id + ' processor compilation failed');
if (!error) {
error = {};
View
10 public/js/spike.js
@@ -143,7 +143,7 @@ function restore() {
}
// Save (scroll) data about the current state of the page, and reload it.
-function reload(event) {
+function reload() {
store.set({
y: window.scrollY,
x: window.scrollX
@@ -155,10 +155,14 @@ function reload(event) {
* Manage the render stream. Wait for processed versions of the author's code,
* and either reload of inject the new code (CSS).
*/
-function renderStream() {
+function liveReload() {
es.addEventListener('css:processed', function (event) {
// Inject the CSS
var style = document.getElementById('jsbin-css');
+ if (!style) {
+ return reload();
+ }
+
if (style.styleSheet) {
style.styleSheet.cssText = event.data;
} else {
@@ -233,7 +237,7 @@ function startStream() {
if (codecasting) {
codecastStream();
} else {
- renderStream();
+ liveReload();
}
if (window.jQuery) {
var $document = $(document);

No commit comments for this range

Something went wrong with that request. Please try again.