Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"we releazied we are doing it wrong" #11

Open
zimt28 opened this issue Mar 1, 2015 · 3 comments
Open

"we releazied we are doing it wrong" #11

zimt28 opened this issue Mar 1, 2015 · 3 comments

Comments

@zimt28
Copy link

zimt28 commented Mar 1, 2015

Please specify, what exactly is wrong with the old approach. The motivation behind flow-components would be easier to grasp :)

@smeijer
Copy link

smeijer commented May 7, 2015

I'm having difficulties to see the benefit of using components as well. I'm trying to compare the two, to see the differences. But the demo's in the readme are pretty much just a Template. I've ported the demo to show you it's hard to see any difference.

I'm not saying that this is the way to go, I would implement this demo in a different way for sure, just tried to make them look the same to make my point more clear.


Component from readme

<template name="hello-component">
  <div class="hello-component">
    Welcome Message: {{state$message}}
  </div>
</template>
var component = FlowComponents.define('hello-component', function(props) {
  console.log("A component created!");
  this.name = props.name;

  this.setRandomGreeting();
  // change the greeting for every 300 millis
  setInterval(this.setRandomGreeting.bind(this), 300);
});

component.prototype.setRandomGreeting = function() {
  var greetings = ["awesome", "nice", "cool", "kind"];
  var randomGreeting = greetings[Math.floor(greetings.length * Math.random())];
  this.set("greeting", randomGreeting)
};

component.state.message = function() {
  return this.name + ", you are " + this.get("greeting") + "!";
};
<body>
  {{> render component="hello-component" name="Arunoda"}}
  {{> render component="hello-component" name="Sacha"}}
</body>

Template port of hello-component

<template name="helloComponent">
  <div class="hello-component">
    Welcome Message: {{message}}
  </div>
</template>
Template.helloComponent.onCreated(function() {
  console.log("A template created!");
  this.name = this.data.name;

  this.greeting = new ReactiveVar("awesome");
  // change the greeting for every 300 millis
  setInterval(setRandomGreeting.bind(this), 300);
});

var setRandomGreeting = function() {
  var greetings = ["awesome", "nice", "cool", "kind"];
  var randomGreeting = greetings[Math.floor(greetings.length * Math.random())];
  this.greeting.set(randomGreeting);
};

Template.helloComponent.helpers({
  'message': function() {
    var instance = Template.instance();
    return instance.name + ", you are " + instance.greeting.get() + "!";
  }
});
<body>
  {{> helloComponent name="Arunoda"}}
  {{> helloComponent name="Sacha"}}
</body>

@smeijer
Copy link

smeijer commented May 7, 2015

Same idea, just a bit more Meteor style:

<template name="helloComponent">
  <div class="hello-component">
    Welcome Message: hello {{name}}, you are {{greeting}}!
  </div>
</template>
var greetings = ["awesome", "nice", "cool", "kind"];

Template.helloComponent.onCreated(function() {
  var instance = this;
  instance.greeting = new ReactiveVar(_.sample(greetings));

  // change the greeting for every 300 millis
  Meteor.setInterval(function() {
    var greet = _.sample(greetings);
    instance.greeting.set(greet);
  }, 300);
});

Template.helloComponent.helpers({
  'greeting': function() {
    var instance = Template.instance();
    return instance.greeting.get();
  }
});
<body>
  {{> helloComponent name="Arunoda"}}
  {{> helloComponent name="Sacha"}}
</body>

To be clear, I'm not trying to be negative about flow-components. I'm a big fan of your work. Just hoping you can make the benefits of using components more clear. I'm sure they are there, otherwise you wouldn't have created this project.

@balint42
Copy link

+1
I would also very much appreciate a more detailed explanation of the motivation. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants