ViewModel 2 - A new level of simplicity

I added .child in v3.1.0 (I also updated the documentation)

The reasoning is that if it makes sense for ViewModel.find to have the .findOne counterpart, then it makes sense for .children to have a .child too.

So you’re now able to use div($b= "text: child('childVM').someProperty"), but I have a feeling you can probably do it with a reference to the child too.

3 Likes

@manuel,
Can I use ref-binded property in VM.share?
This doesn’t work:

<template name="binding">
  <input {{b "ref: color"}} >
</template>

ViewModel.share({
  car: {
    color: ''
  }
});
Template.binding2.viewmodel({
  share: 'car'
});

Ref is for subtemplates, not for html elements. This way, ref doesn’t keep value, but a reference to subtemplate object.

Use viewmodel bindings instead.

@avalanche1

I think you meant to use <input {{b "value: color"}} > (not ref)

@brajt

You can get a hold of elements with ref as well. An example is when you want to apply a JS function to an element:

<template name="example">
  <select {{b "ref: countriesElement, options: countries"}} ></select>
</template>
Template.example.viewmodel({
  countries: ["Afghanistan", "Bahrain"],
  onRendered: function() {
    this.countriesElement.dropdown();
  }
});

btw, I just added a new binding, refGroup, which allows you to manipulate multiple elements at a time.

<template name="example">
  <select {{b "refGroup: dropdowns, options: countries"}} ></select>
  <select {{b "refGroup: dropdowns, options: people"}} ></select>
</template>
Template.example.viewmodel({
  countries: ["Afghanistan", "Bahrain"],
  people: ["Alan", "Brito"],
  onRendered: function() {
    this.dropdowns.dropdown();
  }
});
1 Like

@manuel I saw a version bump and a video explaining some of the changes, but unfortunately it’s unavailable to me (?).
Perhaps it good to write a little about it here too?

For the video see https://viewmodel.meteor.com/about

For the changes see https://github.com/ManuelDeLeon/viewmodel/blob/master/HISTORY.md

wow! a whole new ‘videos’ section in the docs and no mention here?? :shaking_finger_at_Manuel:

Manuel, why would this error appear on every hot code reload?

It usually appears when you use two same children templates without setting vmTag for them.

Yeah, the 2 known ways HCP gets confused are documented here https://viewmodel.meteor.com/docs/misc#hotcodepush

There is one case which I haven’t been able to reproduce because it rarely happens but only in dev mode.

@avalanche1 if you can give me a repro I’ll take a look.

Just to make sure, where do you prefer to have questions asked recently, on forums, in the help section of docs or through issues?

For questions (how do I…? Is it okay to…? etc.) https://viewmodel.meteor.com/help

For issues (this isn’t working…) https://github.com/ManuelDeLeon/viewmodel/issues

Use the forum and medium to tell people how much you love ViewModel =)

1 Like

If we use forum for question - then this topic will be constantly active and thus constantly attract people to get to learn about Viewmodel.

Although I understand @manuel to separate and tunnel questions and issues I do believe that a more active topic in the Meteor forum will give a larger exposure of this great package. Especially since manuel is always active helping out and searching for even better solutions without breaking backwards compatibility. So @avalanche1 I’m with you about that!

Personally very interested in the possible upcoming version with React: See the following ViewModel help forum entry

Well, of course you guys should do what you feel is best and I’ll be okay with it, but I think a more effective way is to let people know about ViewModel when they ask questions on how to do things with Blaze ("hey, there’s a better way… ")

My 2c

But it won’t be easily browsable, especially on low end desktops and phones, where Discourse is pretty slow. When I look for solution to particular problem, I can read the topics in help/issues, but I have to dig through the whole thread on forums.

People on Gitter and Slack are already telling jokes about me doing that on daily basis. :stuck_out_tongue:

1 Like

@manuel https://viewmodel.meteor.com has been down all day. Is there some other way to view the documentation?
I found a github repo, but it seems to be an old version.

By the way, I love viewmodel. I used blaze components on my last project and viewmodel just makes so many things way easier!

I’m sorry but *.meteor.com hosting is having problems right now. Hopefully it will be back online soon.

lol, it’s up now…

Looks like they moved it to more stable server, the casual *.meteor.com apps are still down, but I see Viewmodel and Blaze Components working fine now.