Giter VIP home page Giter VIP logo

Comments (10)

helarqjsc avatar helarqjsc commented on May 18, 2024

Good idea. It could be compiled to something like this:

Object.keys(obj).map(function(value, index) {
   //...
});

to make it work properly in context of React. Each item would have to be called as obj[value] though, which is a bit ugly, but I can't come up with a better solution

from jsx-control-statements.

AlexGilleran avatar AlexGilleran commented on May 18, 2024

What's the advantage over just writing <For each="key" of={Object.keys(obj)}> ?

Doing this would mean we'd have to put code into every for loop that checks whether it's an object or an array, so I'm pretty reticent to do it unless there's a more pressing reason than saving a few keystrokes.

from jsx-control-statements.

jimfb avatar jimfb commented on May 18, 2024

@AlexGilleran Agree. <For each="key" of={Object.keys(obj)}> seems sufficient.

from jsx-control-statements.

rattrayalex avatar rattrayalex commented on May 18, 2024

Would <For k="key" v="val" over="obj" > (ie; using different props) make the implementation any simpler?

from jsx-control-statements.

jimfb avatar jimfb commented on May 18, 2024

Personally I would rather keep the For tag API simple and easy to understand, and let people just call Object.keys(), rather than introduce new syntax/props for iterating over objects instead of sets. Otherwise, what should the tag do if you specify k/v while iterating over a list? Throw? Both contain the same value? eeh, I really don't see any downside to people just using Object.keys. But I do see downside to having people learn new syntax that they don't already know to use the component properly (increased learning curve).

from jsx-control-statements.

rattrayalex avatar rattrayalex commented on May 18, 2024

Otherwise, what should the tag do if you specify k/v while iterating over a list? Throw?

Yes, it should throw.

It's just annoying to have to both do Object.keys and obj[key]. But I'm coming from a CoffeeScript background, where easy object looping is a thing; now that I'm in ES6 (as are many others), I have to get used to Object.keys anyway.

I think this is fine as-is. But it might be worth adding an example to the docs.

from jsx-control-statements.

jimfb avatar jimfb commented on May 18, 2024

+1 for an example of using Object.keys in the docs, since it's not necessarily super obvious and would be a good thing to demo.

from jsx-control-statements.

AlexGilleran avatar AlexGilleran commented on May 18, 2024

Yeah that makes sense, I will get on that.

from jsx-control-statements.

AlexGilleran avatar AlexGilleran commented on May 18, 2024

Documentation updated in 1.1.1

from jsx-control-statements.

jimfb avatar jimfb commented on May 18, 2024

Sweet!

from jsx-control-statements.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.