Skip to content
This repository was archived by the owner on Sep 6, 2019. It is now read-only.

Replace Native JS CodeΒ #14

@k15a

Description

@k15a

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

  1. Setting up the model to hold all of the rules. (similar to https://github.com/evancz/elm-sortable-table)
  2. 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)
  3. Calling styled with 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions