choojs / nanocomponent-adapters

🔌 - Convert a nanocomponent to a component for your favourite API or library (web components, (p)react, angular)
MIT License
96 stars 17 forks source link

Add preact to nanocomponent adapters #4

Closed tkh44 closed 7 years ago

tkh44 commented 7 years ago

Preact does not have createClass. You can emulate it of course, but I did not know if you wanted to do that. Just let me know what you think and I will update PR if needed.

2

yoshuawuyts commented 7 years ago

This is really cool! - whatever is most native to preact is ideal I think; don't think using createClass is desirable then (not even sure that's the best idea for react now haha - is it?)

Also I wonder: would it be better to use prototype methods? I know it's quite common in the preact / react world but it might save some compilation if we use prototypes. Some quick googling makes it seem we can replace:

class Clx extends preact.Component {}

with:

function Clx () {}
Clx.prototype = Object.create(preact.Component)
Clx.prototype.constructor = preact.Component

What do you think?

tkh44 commented 7 years ago

That was what I was going to suggest. I did a quick test here (See Demo component) and it works fine. I wasn't sure if preact was doing any special tricks.

yoshuawuyts commented 7 years ago

cool! :D

On Mon, Jan 30, 2017 at 3:20 PM Kye Hohenberger notifications@github.com wrote:

That was what I was going to suggest. I did a quick test here (See Demo component) http://codepen.io/tkh44/pen/oBpVqd?editors=0010#0 and it works fine. I wasn't sure if preact was doing any special tricks.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/yoshuawuyts/nanocomponent-adapters/pull/4#issuecomment-276224004, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWlelRNpQh40jhLKeZhQOLlWvtBL_TFks5rXnBMgaJpZM4Lx-do .

tkh44 commented 7 years ago

Converted to es5.

yoshuawuyts commented 7 years ago

Rad! - oh also @toddself just pointed out we can now just reuse the react and preact code; e.g. alias it - that's like really cool :D

On Mon, Jan 30, 2017 at 4:07 PM Kye Hohenberger notifications@github.com wrote:

Converted to es5.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/yoshuawuyts/nanocomponent-adapters/pull/4#issuecomment-276232959, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWlelJ-FOPgIXZMfHaZ2GY8iG_oddZkks5rXntDgaJpZM4Lx-do .

yoshuawuyts commented 7 years ago

v1.2.0 :sparkles:

developit commented 7 years ago

Heh - I didn't even need to say anything lol. Regarding prototype methods, preact doesn't care what gets used - the only requirement is that there is a render() method on the prototype. "Inheriting" from Component is just to get setState().