-
Notifications
You must be signed in to change notification settings - Fork 3
Description
I'm working on an issue (cloudinary-community/cloudinary-util#53) that makes use of CloudinaryImage.effect()
The current version passes a string (and it works without typing (ie using any)), but CloudinaryImage.effect only takes EffectActions. I couldn't figure out how it still worked until I got here.
Cloudinary.effect() is basically passed straight through to Transformation.effect here:
js-transformation-builder-sdk/src/transformation/Transformation.ts
Lines 203 to 205 in 61a3606
| effect(effectAction: EffectActions): this { | |
| return this.addAction(effectAction); | |
| } |
Which in turn is passed straight to Transformation.addAction.
js-transformation-builder-sdk/src/transformation/Transformation.ts
Lines 48 to 61 in 61a3606
| addAction(action: Action | string): this { | |
| let actionToAdd: Action | RawAction; | |
| if (typeof action === 'string') { | |
| if (action.indexOf('/') >= 0) { | |
| throw 'addAction cannot accept a string with a forward slash in it - /, use .addTransformation() instead'; | |
| } else { | |
| actionToAdd = new RawAction(action); | |
| } | |
| } else { | |
| actionToAdd = action; | |
| } | |
| this.actions.push(actionToAdd); | |
| return this; | |
| } |
The original call worked with a string because addAction takes a string or an Action, which seems really good. Many Cloudinary users I expect are used to thinking about string values for these things, or at least would expect that to work (ie img.effect('e_tint:40:253f8c)alongsideimg.effect(Adjust.tint('40:253f8c'))`.
Proposed solution:
Update all of the methods for Transformation that pass their parameters along to addAction to accept a string as well as their assigned transform type.