zhouzhuojie / meteor-vue

Vue for Meteor
130 stars 8 forks source link

Suggestion: Remove Cooffescript #13

Closed gil0mendes closed 9 years ago

gil0mendes commented 9 years ago

Hey, I'm starting with Vue and Meteor... and I see your packet on atmosphere so I add it to my new project.

Continuing... at the end of the installation I found that has a dependency coffeescript... You only have one file in coffeescript, so you could rewrite it in JavaScript and so removing a unnecessary dependencies for most users. ;)

codebryo commented 9 years ago

:P I use coffeescript in every meteor project. But agree on changing it to get rid of an extra dependencie.

codebryo commented 9 years ago

I just tried to create a PR and changing the code to JavaScript. After simplifying it as much as possible it's still messy. That's why CoffeeScript usually is awesome.

var Vue, p;

Vue = this.Vue;
p = Vue.prototype;

p.__init = p._init;

p._init = function(option) {
  var self = this;

  self.$$syncDict = {};
  self.__init(_.omit(option, 'sync'));

  if ((option !== null ? option.sync : void 0) != null) {

    _.each(option.sync, function(rxFunc, key) {
      return self.$sync(key, rxFunc);
    });

  }  
};

p.$unsync = function(key) {
  var _ref;
  if ((ref = this.$$syncDict[key]) != null) {
    if (typeof ref.stop === "function") {
      ref.stop();
    }
  }
};

p.$sync = function(key, rxFunc) {
  var self = this;
  self.$unsync(key);

  if (_.isFunction(rxFunc)) {
    self.$$syncDict[key] = Tracker.autorun(function() {
      var val = rxFunc.call(_this);

      if (val != null) {

        if (val.fetch != null) {
          return self.$set(key, val.fetch());
        } 
        else {
          return self.$set(key, val);
        }

      }
    };
  }
};

Vue.config.delimiters = ['[[', ']]'];

A Review of this would be nice imo.

nerijunior commented 9 years ago

@Codebryo I rewrited the coffeescript to javascript to fix the issue #10 in pull #17