ManuelDeLeon / viewmodel-react

Create your React components with view models.
MIT License
24 stars 3 forks source link

If and Unless bindings don't work alongside repeat binding #25

Open antoninadert opened 7 years ago

antoninadert commented 7 years ago

I have this render function:

myComponent({
  fakeData: [
    {id: 1, title: 'Loading', description:'please wait'},
    {id: 2,title: 'Loading', description:'please wait'},
    {id: 3,title: 'Loading', description:'please wait'}
  ],
  isRendered:false,
  rendered() {
    this.isRendered (true)
  },
  render() {
    <ul>
      <li b="unless:isRendered, repeat: fakeAds, key:id">
        <span b="text: repeatObject.title + ' ' +repeatObject.description"></span>
      </li>
    </ul>
  }
});

I need it because I will display different things according to if the data comes from server-side or client-side (mainly because I cannot display things from databases in the server-side, probably because of another vm problem)

But apparently this throws a big error, extract: at BabelCompiler.<anonymous> (packages/babel-compiler.js:114:26) at Array.forEach (native) at BabelCompiler.BCp.processFilesForTarget (packages/babel-compiler.js:113:14)

ManuelDeLeon commented 7 years ago

Pretty sure it's a bug when using unless + repeat. Try it with if: !isRendered, ...

antoninadert commented 7 years ago

I tried and it does the same problem with if bindings as well

antoninadert commented 7 years ago

Just for information I saw a Vue.js warning in some coding video, saying "It is not recommended to use if and for loops in the same node" maybe there are reasons not to do it in VM as well?

I was kind of surprised vue has the same limitation but this may make sense...