monolite icon indicating copy to clipboard operation
monolite copied to clipboard

Better README with Documentation

Open kube opened this issue 8 years ago • 9 comments

kube avatar Feb 01 '17 23:02 kube

I would add a note about requiring Proxy support. Sadly I can't use it. :(

spacejack avatar Apr 13 '17 02:04 spacejack

@spacejack This is something that I'm already aware, but did not take time to fix: You can check https://github.com/kube/monolite/issues/2 for more information.

I'm currently working on Electron applications, so I don't have this kind of issue right now, but as I will have soon to target browsers again, I need to find a solution for that.

What kind of build process do you use? This should be easily fixed, but my real problem is to find the correct tool to use.

TypeScript

Using TypeScript compiler would need to create a custom transpiler using TypeScript API, which would do the transformation before calling the real TypeScript compiler.

The goal of this transpiler would only be to resolve the Accessor Function statically.

It would mean another build process step, as it's currently not possible to plug custom AST transform functions in the TypeScript compiler.

Another solution would be to create a wrapper around the TypeScript compiler, and call this custom compiler for Production. But it's kinda strange to create a wrapper of TSC for just one little functionality.

Babel

Babel provides a simple way to plug custom transform functions, but it would mean to use both TypeScript AND Babel during build.


I still did not decide which solution I would choose.

What kind of build process did you setup? Also, do you use Webpack or Gulp? What environments are you targeting?

kube avatar Apr 13 '17 13:04 kube

I'm using pretty minimalist tooling - so browserify/tsify. I'm not sure I'd add additional tooling just for this unless I was going to make heavy use of it. Possibly on a future project though.

Babel seems like a reasonable approach, though I haven't spent a lot of time looking at how to add Babel to my pipeline.

spacejack avatar Apr 13 '17 16:04 spacejack

Just a little question about what your target is:

If you target browsers in general, and performance in old browsers (those that do not support ES2015) is not a real problem, there's a way to add support (in a dirty way).

Today I use a Proxy to convert Accessor Function to Accessors Chain, but this could fall back on a Regex-based resolution if there's no support for Proxy.

Something like:

const getAccessorChainWithoutProxy = (accessorFn: Function) =>
  accessorFunction.toString().match(/someregexhere/).andSomeAdditionalTransform()

It's not a clean way to achieve this, and would not be really performing, but has the benefit to work out of the box, even during development, until the Babel plugin is available (and even after).

Maybe even it could be cached if there's a way to detect accessorFunction identity equality.

Would this be something useful for you?

kube avatar Apr 13 '17 16:04 kube

Yeah, definitely. I'd probably use it if that were in place. I doubt performance would be an issue in my case and am not too concerned about it on IE or old Android Browser anyway - just so long as it works.

spacejack avatar Apr 13 '17 17:04 spacejack

I will add support for ES5 this week-end.

kube avatar Apr 14 '17 11:04 kube

Just for info, I started the Babel plugin: https://github.com/kube/babel-plugin-monolite

You can already install it using NPM

npm install --save-dev babel-plugin-monolite

It's still in really early stage, but I would love any feedback on it.

kube avatar Apr 28 '17 23:04 kube

I have a slightly unrelated question - is the usage of proxies a performance hazard for a Node JS backend? I'm getting away from ImmutableJS and trying to find a safe spot to land.

Also, I believe Typescript is getting to the place where plugins will be possible pretty soon.

bryanerayner avatar Jun 20 '17 04:06 bryanerayner

@bryanerayner Just did a little Google search, and the first article seems to say that performance is not heavily impacted by usage of Proxy:

http://dealwithjs.io/es6-features-10-use-cases-for-proxy/#performance

But one thing is that Proxies and Reflection in general make harder JIT optimisation. I did not make a benchmark myself at the moment, but it's something I'm gonna need to do soon.

If you have a real need of performance, I suggest you to use the Babel Monolite Plugin. It's still early stage, but it will permit to resolve accessors statically.

Let me know if you start using it, I would really like to have feedback on it. (And enhance it too)

kube avatar Jun 26 '17 21:06 kube