Knockout: JSX + ko components ?

Created on 27 Dec 2014  路  5Comments  路  Source: knockout/knockout

i'm an amateur js developer and i absolutely love knockoutjs !
i have an idea and i what to share it with you.
here it is :

(i): knockout components are great but the html part is a string literal
(ii): being able to see both html (template) and js (view model) code in one place is great
(iii) : we have already an answer for (ii) => JSX
(iv): code editors already support JSX syntax | at least are going to support it

(i),(ii),(iii),(iv) => we should write a JSX compiler for knockout components . (right?)

here is a simple example :
https://github.com/aminroosta/konckout-sample-jsx-compiler/blob/master/index.html

i want to know your opinion , do you think that it does worth the effort ?

Most helpful comment

+1 For the implications of the design-time syntax checking that JSX with TypeScript enables. I like knockout but hate working with strings like we have to.

All 5 comments

Sounds kind of interesting. I generally have put markup in separate files and use a module system (like text plugin for require.js) to pull them in. However, when doing work with React recently, I found JSX to be pleasant to work in. I'll close this, as this would be a good candidate for a plugin vs. something to pursue for KO code. If you ever do develop such a plugin, feel free to link to it here. Thanks for posting!

TypeScript is proposing to extend their compiler to permit compilation of files containing JSX.

See Microsoft/TypeScript#3203.

If this goes ahead then ReactJS will have a competitive advantage over KnockoutJS.

That is because syntax and semantic errors in JSX will be checked at compile time for ReactJS, while for Knockout these errors will only become apparent at runtime (if at all).

I propose this issue be re-opened and Knockout consider providing native support for JSX.

I support aminroosta and his very clear points, moreover I believe that jsx support is the next logical step for knockout components and knockout overall.

however I'd like to make a few other points

  • I also want an internal ko parser as environments vary and having external compiler for jsx may not be always an option
  • not sure how opening bracket can be legal in js(x) file - so something along these lines also seems good enough as well binding proposal and jsx key being the key identifying the view type (string literal or jsx)

+1 For the implications of the design-time syntax checking that JSX with TypeScript enables. I like knockout but hate working with strings like we have to.

Great idea, and with tsx this would be truly type-safe.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andersekdahl picture andersekdahl  路  6Comments

johnpapa picture johnpapa  路  9Comments

azaslonov picture azaslonov  路  3Comments

mcarpenterjr picture mcarpenterjr  路  3Comments

brunolau picture brunolau  路  8Comments