Beispiel #1
0
 load(path, js, function (err) {
   if (err) row.fail(err);
   defer(function () {
     try { fakeRequire(path); }
     catch (err) { row.fail(err); }
   });
 });
Beispiel #2
0
 function backgroundFetch() {
   // Mark ftime so we don't start another fetch while this is running.
   meta.ftime = now;
   // Defer so it can't interfere with the current stack.
   defer(function () {
     fetch(repo, ref, meta.hash, onUpdate);
   });
 }
Beispiel #3
0
 load("vfs:/"+row.path, editor.getText(), function (err, js) {
   if (err) row.fail(err);
   defer(function () {
     try {
       notify(reload(row.path, js)+' modules reloaded.');
     } catch (err) {
       row.fail(err);
     }
   });
 });
Beispiel #4
0
function renderChild(path, mode, hash) {
  var row = rows[path];
  if (row) {
    row.mode = mode;
    row.errorMessage = "";
    // Skip nodes that haven't changed
    if (row.hash === hash) {
      return row;
    }
    row.hash = hash;
  }
  else {
    row = rows[path] = makeRow(path, mode, hash);
  }

  // Defer further loading so the row can render before it hits any problems.
  defer(function () {
    if (mode === modes.commit) row.call(fs.readCommit, onCommit);
    else init();
  });

  return row;

  function onCommit(entry) {
    if (!entry) throw new Error("Missing commit");
    var commit = entry.commit;
    var head = entry.head || {};
    row.hash = entry.hash;
    row.treeHash = commit.tree;
    var config = fs.configs[row.path];
    row.ahead = config.ahead || 0;
    row.behind = config.behind || 0;
    row.staged = commit.tree !== head.tree;
    row.title = formatDate(commit.author.date) + "\n" + commit.author.name + " <" + commit.author.email + ">\n\n" + commit.message.trim();
    init();
  }

  function formatDate(date) {
    var d = new Date(date.seconds * 1000);
    // TODO: find a way to show the original time zone?
    return d.toString();
  }

  function init() {
    if ((mode === modes.tree || mode === modes.commit) && openPaths[path]) openTree(row);
    if (activePath && activePath === path) activateDoc(row, !selected);
  }

}
Beispiel #5
0
function renderChild(path, mode, hash) {
  var row = rows[path];
  if (row) {
    row.mode = mode;
    row.errorMessage = "";
    // Skip nodes that haven't changed
    if (row.hash === hash) {
      return row;
    }
    row.hash = hash;
  }
  else {
    row = rows[path] = makeRow(path, mode, hash);
  }

  // Defer further loading so the row can render before it hits any problems.
  defer(function () {
    if (mode === modes.commit) row.call(fs.readCommit, onCommit);
    else init();
  });

  return row;

  function onCommit(entry) {
    if (!entry) throw new Error("Missing commit");
    var commit = entry.commit;
    var head = entry.head || {};
    row.hash = entry.hash;
    row.treeHash = commit.tree;
    row.staged = commit.tree !== head.tree;
    row.title = commit.author.date.toString() + "\n" + commit.author.name + " <" + commit.author.email + ">\n\n" + commit.message.trim();
    init();
  }

  function init() {
    if ((mode === modes.tree || mode === modes.commit) && openPaths[path]) openTree(row);
    if (activePath && activePath === path) activateDoc(row, !selected);
    // var hookConfig = hookConfigs[row.path];
    // if (hookConfig && hookConfig.port && !hooks[row.path]) {
    //   hooks[row.path] = addServeHook(row, hookConfig);
    // }
  }

}
Beispiel #6
0
 function writeEntry(path, entry, callback) {
   if (!callback) return writeEntry.bind(null, path, entry);
   if (!pendingWrites) {
     // Start recording writes to be written
     pendingWrites = {};
     writeCallbacks = [];
     // Defer starting the write to collect more writes this tick.
     defer(writeEntries);
   }
   if (!path) {
     if (!entry.hash) {
       return callback(new Error("Root cannot be deleted"));
     }
     if (entry.mode !== modes.commit) {
       return callback(new Error("Only commits can be written to root"));
     }
   }
   pendingWrites[path] = entry;
   if (callback) writeCallbacks.push(callback);
 }
Beispiel #7
0
function renderChild(path, mode, hash) {
  var row = rows[path];
  if (row) {
    row.mode = mode;
    row.errorMessage = "";
    // Skip nodes that haven't changed
    if (row.hash === hash) {
      return row;
    }
    row.hash = hash;
  }
  else {
    row = rows[path] = makeRow(path, mode, hash, newRows[path]);
    delete newRows[path];
  }

  // Defer further loading so the row can render before it hits any problems.
  defer(function () {
    if (mode === modes.commit) {
      row.call(fs.readCommit, function(entry) {
        var behindIcon, aheadIcon;
        
        onCommit(entry);

        if (path) {
          getBehind(row, entry);
          if (row.mode === modes.commit) {
            behindIcon = row.rowEl.getElementsByClassName('icon-download-cloud')[0];
            if (behindIcon) {
              behindIcon.removeEventListener('click', behindIconClick);
              behindIcon.addEventListener('click', behindIconClick);
            }
            aheadIcon = row.rowEl.getElementsByClassName('icon-upload-cloud')[0];
            if (aheadIcon) {
              aheadIcon.removeEventListener('click', aheadIconClick);
              aheadIcon.addEventListener('click', aheadIconClick);
            }
          }
        }
      });
    } else {
      init();
    }

    reloadIframe();
  });

  return row;

  function reloadIframe() {
    var iframe = pageIframe.get();
    var contentWindow = iframe && iframe.contentWindow;
    var System = contentWindow && contentWindow.System;

    if (System && System.reload) {
      fs.readBlob(path, function (err, entry) {
        if (!err && entry && entry.hash && entry.blob !== undefined) {
          try {
            if (System.reload(path, bodec.toUnicode(entry.blob))) {
              notify('Reloaded '+path);
            }
          } catch (err) {
          }
        }
      });
    }
  }

  function onCommit(entry) {
    if (!entry) throw new Error("Missing commit");
    
    var commit = entry.commit;
    var head = entry.head || {};
    
    row.hash = entry.hash;
    row.treeHash = commit.tree;
    
    var config = fs.configs[row.path];

    row.ahead = config.ahead || 0;
    row.behind = config.behind || 0;

    row.dirty = config.dirty || row.path !== '' && commit.tree !== head.tree;
    row.committed = config.committed || false;

    row.title = formatDate(commit.author.date) + "\n" + commit.author.name + " <" + commit.author.email + ">\n\n" + commit.message.trim();

    init();
  }

  function formatDate(date) {
    var d = new Date(date.seconds * 1000);
    // TODO: find a way to show the original time zone?
    return d.toString();
  }

  function init() {
    if ((mode === modes.tree || mode === modes.commit) && openPaths[path]) openTree(row);
    if (activePath && activePath === path) activateDoc(row, !selected);
  }

}
Beispiel #8
0
 setRootTree: function (hash, callback) {
   rootTree = hash;
   rootTime = Date.now();
   defer(saveRoot);
   callback();
 }
Beispiel #9
0
 storage.get("prefs", function (items) {
   prefs = items.prefs || {};
   // This is deferred to workaround chrome error reporting issues.
   defer(callback);
 });
Beispiel #10
0
 function setRoot(hash) {
   if (!hash) throw new Error("Missing root hash");
   platform.setRootHash(hash);
   defer(function () { change(hash); });
 }