kube / monolite

Statically-typed structural-sharing tree modifier
https://www.npmjs.com/package/monolite
148 stars 6 forks source link

Possibility for IE11 support? #32

Closed blackwood closed 6 years ago

blackwood commented 6 years ago

Since Proxy isn't available in IE11, wondered if there's a transpilation addon for babel or recommended polyfill, or if this library could benefit from using feature detection to provide an alternative to the Proxy used in accessorChain.ts. If you're open to a pull request, or have any ideas, let me know!

kube commented 6 years ago

Sorry for anwering your question so late.

There is an old (and far from perfect) Babel plugin to statically transform the accessor functions to accessor chains and prevent usage of Proxy:

https://github.com/kube/babel-plugin-monolite

I'd like to rewrite it as a plugin for ts-loader or something that would not need to add Babel to the compilation pipeline.

kube commented 6 years ago

Just to have an idea, what is your current compilation pipeline?

kube commented 6 years ago

@blackwood I just updated the Babel Plugin for Monolite to handle the new version 0.7 with fluent-style set.

To install it, simply:

yarn add --dev babel-plugin-monolite

Then in babel.config.js:

module.exports = api => {
  api.cache(true)

  return {
    presets: [
      // ...
    ],
    plugins: [
      'babel-plugin-monolite'
    ]
  }
}

This will transform all accessor functions to accessor chains statically, preventing usage of Proxy at runtime, and thus making your code compatible with IE9+.

// BEFORE
set(state, _ => _.a.b[c], 42)

// AFTER
set(state, ['a', 'b', c], 42)
blackwood commented 6 years ago

Hello, sorry for the delay in response and thanks for the update and compatibility fix!

kube commented 6 years ago

@blackwood Beware that nested set fail for now. (https://github.com/kube/monolite/issues/40)

I will fix that soon (Babel plugin will be reworked). It will also be bundled directly in the library (https://github.com/kube/monolite/issues/37)

Also created a minimal boilerplate with Babel/Typescript/Webpack/React and Monolite support. (https://github.com/kube/slate)

Please let me know if you find other bugs or anything.