Skip to content

Commit a164479

Browse files
authored
add clone functionality to image (#332)
1 parent c1930d3 commit a164479

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

__TESTS__/unit/utils/clone.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {CloudinaryMedia} from "../../../src/assets/CloudinaryMedia";
2+
import {Effect} from "../../../src/actions/effect";
3+
4+
describe('Tests for cloning', () => {
5+
it('should clone resource', () => {
6+
const asset = new CloudinaryMedia('sample', {cloudName: 'demo'});
7+
8+
const cloneAsset = asset.clone();
9+
10+
//add transformation to asset
11+
asset.effect(Effect.sepia());
12+
13+
//change public id of cloneAsset
14+
cloneAsset.setPublicID('dog');
15+
16+
expect(cloneAsset.toURL()).toEqual('https://res.cloudinary.com/demo/image/upload/dog');
17+
expect(asset.toURL()).toEqual('https://res.cloudinary.com/demo/image/upload/e_sepia/sample');
18+
});
19+
});
20+

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,9 @@
7575
"lunr": "^1.0.0",
7676
"moment": "^2.22.1",
7777
"sanitize-html": "^1.18.2"
78+
},
79+
"dependencies": {
80+
"@types/lodash.clonedeep": "^4.5.6",
81+
"lodash.clonedeep": "^4.5.0"
7882
}
7983
}

src/assets/CloudinaryMedia.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {LayerAction} from "../actions/layer/LayerAction";
55
import {Transformation} from "../transformation/Transformation";
66
import ICloudConfig from "../config/interfaces/Config/ICloudConfig";
77
import IURLConfig from "../config/interfaces/Config/IURLConfig";
8+
import cloneDeep from 'lodash/cloneDeep';
89

910

1011
/**
@@ -50,7 +51,10 @@ class CloudinaryMedia extends CloudinaryTransformable {
5051
toURL(): string {
5152
return this.createCloudinaryURL(this.transformation);
5253
}
53-
}
5454

55+
clone(): this {
56+
return cloneDeep(this);
57+
}
58+
}
5559

5660
export {CloudinaryMedia};

0 commit comments

Comments
 (0)