Clouda-team / Cloudajs

Clouda Framework - A Realtime Javascript RIA Framework For Mobile WebApp
899 stars 403 forks source link

subscribe应可对异常进行处理 #78

Closed imyelo closed 10 years ago

imyelo commented 10 years ago

更理想的写法: publish

fw.publish('something', 'pub-something', function(callback) {
  var options = {
    host: __HOST__,
    path: __PATH__,
    json: true
  };
  var param = {
    foo: 'bar'
  };
  var cb = function (data) {
    var result = [];
    var err;
    try {
      data = JSON.parse(data.toString());
      (data.list instanceof Array) && (result = data.list);
    } catch (e) {
      err = e;
    }
    callback(err, result);
    // or callback(result);
  }
  sumeru.external.post(options, param, cb);
});

subscribe

session.something = env.subscribe('pub-something', somethingId, function(err, collection) {
  var data;
  if (err) {
    console.log(err);
    return session.bind('tpl',{
      err: err,
    });
  }
  return session.bind('tpl', {
    data: collection 
  });
});
tongyao commented 10 years ago

Thanks. 确实应该这么做

On Fri, Dec 6, 2013 at 3:57 PM, yelo notifications@github.com wrote:

较为理想的写法: publish

fw.publish('something', 'pub-something', function(callback) { var options = { host: HOST, path: PATH, json: true }; var param = { foo: 'bar' }; var cb = function (data) { var result = []; var err; try { data = JSON.parse(data.toString()); (data.list instanceof Array) && (result = data.list); } catch (e) { err = e; } callback(err, result); // or callback(result); } sumeru.external.post(options, param, cb); });

subscribe

session.something = env.subscribe('pub-something', somethingId, function(err, collection) { var data; if (err) { console.log(err); return session.bind('tpl',{ err: err, }); } return session.bind('tpl', { data: collection }); });

— Reply to this email directly or view it on GitHubhttps://github.com/brandnewera/clouda/issues/78 .