chainyjs / chainy

The chainy core + autoloader plugin
https://github.com/chainyjs/chainy/wiki
Other
79 stars 4 forks source link

Use proxies to avoid requires #5

Closed balupton closed 10 years ago

balupton commented 10 years ago

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#Very_simple_example

http://wiki.ecmascript.org/doku.php?id=harmony%3aproxies#simulating_nosuchmethod_doesnotunderstand

balupton commented 10 years ago

Doesn't seem like it is there yet:

https://github.com/joyent/node/issues/4138

The other issue here is that we will need to use a synchronous exec to install the extension, as utilities and customs need to be installed right away.


However there is:

https://github.com/tvcutsem/harmony-reflect

Which shims the crappy node harmony methods with the latest working ones.


Using the above with:

node --harmony
var p = new Proxy(require('chainy').create(), {get:function(target, name){ return target[name] || 'fetch '+name } })
p.done // chainy done
p.asd // fetch asd

Works fine. However... it does require the --harmony flag, which is a major pain.


So now just need to figure out exec sync, possible options until node 0.12 is release with exec sync by default:

balupton commented 10 years ago

Closing. Autoloading the installed plugins solves this issue in a different way.

balupton commented 10 years ago

The problem with autoloading is it requires the extensions to be installed, it would be nice if there was a proxy thing plus the autoinstall plugin.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/noSuchMethod could be an option for this

http://stackoverflow.com/questions/7891937/is-it-possible-to-implement-dynamic-getters-setters-in-javascript