File tree Expand file tree Collapse file tree 3 files changed +23
-14
lines changed Expand file tree Collapse file tree 3 files changed +23
-14
lines changed Original file line number Diff line number Diff line change @@ -65,10 +65,10 @@ Opaque object describing a gradient.
65
65
canvasElementToImageSource :: CanvasElement -> CanvasImageSource
66
66
```
67
67
68
- #### ` withImage `
68
+ #### ` tryLoadImage `
69
69
70
70
``` purescript
71
- withImage :: forall eff. String -> (CanvasImageSource -> Eff eff Unit) -> Eff eff Unit
71
+ tryLoadImage :: forall eff. String -> (Maybe CanvasImageSource -> Eff (canvas :: Canvas | eff) Unit) -> Eff (canvas :: Canvas | eff) Unit
72
72
```
73
73
74
74
Wrapper for asynchronously loading a image file by path and use it in callback, e.g. drawImage
Original file line number Diff line number Diff line change @@ -5,16 +5,21 @@ exports.canvasElementToImageSource = function(e) {
5
5
return e ;
6
6
} ;
7
7
8
- exports . withImage = function ( src ) {
9
- return function ( f ) {
10
- return function ( ) {
11
- var img = new Image ( ) ;
12
- img . src = src ;
13
- img . addEventListener ( "load" , function ( ) {
14
- f ( img ) ( ) ;
15
- } , false ) ;
16
-
17
- return { } ;
8
+ exports . tryLoadImageImpl = function ( src ) {
9
+ return function ( e ) {
10
+ return function ( f ) {
11
+ return function ( ) {
12
+ var img = new Image ( ) ;
13
+ img . src = src ;
14
+ img . addEventListener ( "load" , function ( ) {
15
+ f ( img ) ( ) ;
16
+ } , false ) ;
17
+ img . addEventListener ( "error" , function ( error ) {
18
+ e ( ) ;
19
+ } , false ) ;
20
+
21
+ return { } ;
22
+ }
18
23
}
19
24
} ;
20
25
} ;
Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ module Graphics.Canvas
84
84
, restore
85
85
, withContext
86
86
87
- , withImage
87
+ , tryLoadImage
88
88
, getImageData
89
89
, putImageData
90
90
, putImageDataFull
@@ -139,8 +139,12 @@ foreign import data CanvasGradient :: *
139
139
140
140
foreign import canvasElementToImageSource :: CanvasElement -> CanvasImageSource
141
141
142
+ foreign import tryLoadImageImpl :: forall eff . String -> Eff (canvas :: Canvas | eff ) Unit -> (CanvasImageSource -> Eff (canvas :: Canvas | eff ) Unit ) -> Eff (canvas :: Canvas | eff ) Unit
143
+
142
144
-- | Wrapper for asynchronously loading a image file by path and use it in callback, e.g. drawImage
143
- foreign import withImage :: forall eff . String -> (CanvasImageSource -> Eff eff Unit ) -> Eff eff Unit
145
+ tryLoadImage :: forall eff . String -> (Maybe CanvasImageSource -> Eff (canvas :: Canvas | eff ) Unit ) -> Eff (canvas :: Canvas | eff ) Unit
146
+ tryLoadImage path k = tryLoadImageImpl path (k Nothing ) (k <<< Just )
147
+
144
148
145
149
foreign import getCanvasElementByIdImpl ::
146
150
forall r eff . Fn3 String
You can’t perform that action at this time.
0 commit comments