-
Notifications
You must be signed in to change notification settings - Fork 7
Replace Native JS CodeΒ #14
Description
I recently realized that only the elm-lang/core package is allowed to have native JS code. Currently elm-styled is using native JS code to inject the CSS. The problem is that I can't publish elm-styled to the official package manager and users would have to install this package directly from GitHub with tools like elm-github-install. The last couple of days I thought how to remove the native code from elm-styled to finally publish the package. My current solutions are:
Monkey Patching Element.prototype
This would work similar to https://github.com/gdotdesign/elm-html-styles. We would add a new attribute setter to the element prototype and everytime an element is created the styles would inject magically.
Usage
The user would have to inject a single script which monkey patches the elment.prototype.
Pros
- The simplest solution for the users.
- We could use sheet.insertRule() which is very fast.
Cons
- We would have to monkey patch browser internals. (I don't like that)
Ports
Usage
- Setting up the model to hold all of the rules. (similar to https://github.com/evancz/elm-sortable-table)
- Creating a port module and injecting the styles with JavaScript on the other site. / Injecting the styles into a single style tag (probably pretty slow)
- Calling
styledwith an additional argument which is the Msg type to add styles to the model.type Msg = AddStyle Styled.Msg | OtherMsg styled AddStyle div [ padding zero ]
Pros
- No monkey patching of browser internals.
- We could use sheet.insertRule() which is very fast.
Cons
- Much boilerplate which hurts the simplicity of
elm-styled
I would love the get some feedback and suggestions for better solutions.
Maybe someone with more elm experience has a great solution for us.