ManuelDeLeon / viewmodel-react

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

Is repeatObject a reserved keyword (loops) #45

Open antoninadert opened 6 years ago

antoninadert commented 6 years ago

Hi Manuel,

I was looking at the doc:

Colors({
    colors: ['red', 'green', 'blue'],
    selectedColor: '',
    render() {
        <div>
            <ul>
                <Color b="repeat: colors" color={repeatObject} selectedColor={this.selectedColor} />
            </ul>
            Color: <span b="text: selectedColor, style: { color: selectedColor }" />
        </div>
    }
})

And I see a lot of use of this repeatObject. For me it is self-explanatory that this will give me the current color in this example.

That being said, you show this in the example but there is no word about it in the docs.

If I understand correctly, it is a reserved keyword. If you agree I'll try and make a pull request to explain the repeatobject in the loops context

ManuelDeLeon commented 6 years ago

It is quasi-reserved. It's overridden in the repeat block because the repeat binding is rewritten as:

{this.collection().map((repeatObject, repeatIndex) => {
  return <Component />
})}

See http://viewmodel.org/#BindingsRepeat

ManuelDeLeon commented 6 years ago

Feel free to submit any PR that you think will make the project or documentation better =)