Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

Commit 84c26c9

Browse files
committed
Add method for requesting full drawing history
1 parent c5a7718 commit 84c26c9

7 files changed

+105
-192
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ export class AppComponent {
384384
}
385385
}
386386
```
387+
### Requesting the full update history so far
388+
Can be called via the method `getDrawingHistory(): CanvasWhiteboardUpdate[]`. The items will be deep cloned for consistency using lodash.
387389
388390
## Saving drawn canvas as an image
389391
In order to save drawn images you can either click the Save button in the canvas,

dist/canvas-whiteboard.component.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,12 @@ export declare class CanvasWhiteboardComponent implements OnInit, AfterViewInit,
405405
*/
406406
toggleShapeSelector(value: boolean): void;
407407
selectShape(newShapeBlueprint: INewCanvasWhiteboardShape<CanvasWhiteboardShape>): void;
408+
/**
409+
* Returns a deep copy of the current drawing history for the canvas.
410+
* The deep copy is returned because we don't want anyone to mutate the current history
411+
* @returns {CanvasWhiteboardUpdate[]}
412+
*/
413+
getDrawingHistory(): CanvasWhiteboardUpdate[];
408414
/**
409415
* Unsubscribe from a given subscription if it is active
410416
* @param {Subscription} subscription

dist/canvas-whiteboard.component.js

Lines changed: 68 additions & 187 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/canvas-whiteboard.component.metadata.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

package-lock.json

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ng2-canvas-whiteboard",
3-
"version": "2.1.1",
3+
"version": "2.1.2",
44
"description": "A Canvas component for Angular which supports free drawing.",
55
"main": "index.js",
66
"scripts": {
@@ -38,7 +38,9 @@
3838
"custom shapes",
3939
"custom premade shapes"
4040
],
41-
"dependencies": {},
41+
"dependencies": {
42+
"lodash.clonedeep": "4.5.0"
43+
},
4244
"peerDependencies": {
4345
"rxjs-compat": "^6.0.0"
4446
},
@@ -47,6 +49,7 @@
4749
"@angular/compiler-cli": "4.3.2",
4850
"@angular/compiler": "4.3.2",
4951
"@angular/core": "4.3.2",
52+
"@types/lodash": "^4.14.116",
5053
"typescript": "2.2.1",
5154
"rxjs": "5.2.0",
5255
"rxjs-compat": "^6.0.0",

src/canvas-whiteboard.component.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {CanvasWhiteboardPoint} from "./canvas-whiteboard-point";
1818
import {CanvasWhiteboardShapeService, INewCanvasWhiteboardShape} from "./shapes/canvas-whiteboard-shape.service";
1919
import {Observable} from "rxjs";
2020
import {CanvasWhiteboardShapeOptions} from "./shapes/canvas-whiteboard-shape-options";
21+
import * as cloneDeep from "lodash.cloneDeep";
2122

2223
@Component({
2324
selector: 'canvas-whiteboard',
@@ -825,7 +826,7 @@ export class CanvasWhiteboardComponent implements OnInit, AfterViewInit, OnChang
825826
* @return Emits an Array of Updates when the batch.
826827
*/
827828
private _prepareUpdateForBatchDispatch(update: CanvasWhiteboardUpdate): void {
828-
this._batchUpdates.push(update);
829+
this._batchUpdates.push(cloneDeep(update));
829830
if (!this._updateTimeout) {
830831
this._updateTimeout = setTimeout(() => {
831832
this.onBatchUpdate.emit(this._batchUpdates);
@@ -1081,6 +1082,15 @@ export class CanvasWhiteboardComponent implements OnInit, AfterViewInit, OnChang
10811082
this.selectedShapeConstructor = newShapeBlueprint;
10821083
}
10831084

1085+
/**
1086+
* Returns a deep copy of the current drawing history for the canvas.
1087+
* The deep copy is returned because we don't want anyone to mutate the current history
1088+
* @returns {CanvasWhiteboardUpdate[]}
1089+
*/
1090+
getDrawingHistory(): CanvasWhiteboardUpdate[] {
1091+
return cloneDeep(this._updateHistory);
1092+
}
1093+
10841094
/**
10851095
* Unsubscribe from a given subscription if it is active
10861096
* @param {Subscription} subscription

0 commit comments

Comments
 (0)