Elm-Canvas / elm-canvas

Making the canvas API accessible within Elm
BSD 3-Clause "New" or "Revised" License
63 stars 14 forks source link

Elm-Canvas references document, and in some contexts that doesnt exist #71

Open Chadtech opened 6 years ago

Chadtech commented 6 years ago

I was using Elm-Canvas in a project, when Elm-css started erroring with "document is not defined". My work around was adding this code:

var fakeDoc = { 
  createElement: function(){ 
    return { 
      getContext: function() {
        return {
          drawImage: function(){},
          beginPath: function(){},
          rect: function(){},
          fill: function(){},
        }
      } 
    }; 
  }
};

var D = typeof document === "undefined" ? fakeDoc : document;