@leafer/image 1.0.0-beta.4 → 1.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/image",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.5",
4
4
  "description": "@leafer/image",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -19,6 +19,6 @@
19
19
  "leaferjs"
20
20
  ],
21
21
  "devDependencies": {
22
- "@leafer/interface": "1.0.0-beta.4"
22
+ "@leafer/interface": "1.0.0-beta.5"
23
23
  }
24
24
  }
@@ -1,5 +1,6 @@
1
- import { ILeafer, ILeaferCanvasConfig, IImageManager, ILeaferImageConfig, ILeaferImage } from '@leafer/interface'
1
+ import { ILeafer, ILeaferCanvasConfig, IImageManager, ILeaferImageConfig, ILeaferImage, ITaskProcessor, IFunction } from '@leafer/interface'
2
2
  import { Creator } from '@leafer/platform'
3
+ import { TaskProcessor } from '@leafer/task'
3
4
 
4
5
 
5
6
  interface ILeaferImageMap {
@@ -11,10 +12,13 @@ export class ImageManager implements IImageManager {
11
12
 
12
13
  public leafer: ILeafer
13
14
 
15
+ public tasker: ITaskProcessor
16
+
14
17
  public map: ILeaferImageMap = {}
15
18
 
16
19
  constructor(leafer: ILeafer, _config: ILeaferCanvasConfig) {
17
20
  this.leafer = leafer
21
+ this.tasker = new TaskProcessor()
18
22
  }
19
23
 
20
24
  public get(config: ILeaferImageConfig): ILeaferImage {
@@ -26,6 +30,11 @@ export class ImageManager implements IImageManager {
26
30
  return image
27
31
  }
28
32
 
33
+ public load(image: ILeaferImage, onSuccess: IFunction, onError: IFunction): void {
34
+ this.tasker.add(async () => await image.load(onSuccess, onError))
35
+ if (!this.tasker.running) this.tasker.start()
36
+ }
37
+
29
38
  public destory(): void {
30
39
  this.leafer = null
31
40
  this.map = null
@@ -17,8 +17,8 @@ export class LeaferImageBase implements ILeaferImage {
17
17
  this.options = _options
18
18
  }
19
19
 
20
- public load(onSuccess: IFunction, onError: IFunction): void {
21
- Platform.origin.loadImage(this.options.url).then((img) => {
20
+ public async load(onSuccess: IFunction, onError: IFunction): Promise<void> {
21
+ return Platform.origin.loadImage(this.options.url).then((img) => {
22
22
  this.ready = true
23
23
  this.width = img.naturalWidth || img.width
24
24
  this.height = img.naturalHeight || img.height