cyclejs / todomvc-cycle

TodoMVC example implemented in Cycle.js
https://cyclejs.github.io/todomvc-cycle/
MIT License
240 stars 62 forks source link

Refactor propHook to avoid using class + this (to support goal of thisless JavaScript) #20

Closed acusti closed 8 years ago

acusti commented 8 years ago

Apologies for this pedantic nitpick. With that disclaimer, I found this repo after reading the Cycle.js homepage, where it says:

thisless JavaScript: The use of functions and RxJS Observables allow for a JavaScript programming style without the this keyword. Cycle.js encourages you to create apps with functional practices. Without this, you can write more reusable code and define logic without tightly coupling it to data. See it for yourself, this cannot be found in Cycle.js TodoMVC.

The current implementation of propHook uses this, so I thought I’d propose implementing that utility differently to validate the “thisless JavaScript” assertion.

Frikki commented 8 years ago

@acusti Good catch.

staltz commented 8 years ago

This has been discussed before https://github.com/cyclejs/todomvc-cycle/pull/14.

propHook needs this because that's how hooks work in virtual-dom. TBH propHook is a util. Could have been a library, then you wouldn't see the this at all. It's a virtual-dom thing, not a Cycle.js thing. I know virtual-dom is part of Cycle DOM, but still, it's just one driver. Perhaps if we build a new Cycle DOM based on some other virtual DOM library that has a thisless API, then we can achieve that.

The point here is: as far as Cycle.js and RxJS is concerned, ignoring some corner cases in some drivers, there are no this.

I'll update the docs page to remove the sentence "See it for yourself, this cannot be found in Cycle.js TodoMVC.". But that doesn't mean much in my opinion. You still rarely or never see a this. What matters most, you don't need to think or reason about this.