Skip to content

Commit

Permalink
fix: Fix set method for fixedProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed Oct 21, 2019
1 parent 54159ab commit 2752092
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 20 deletions.
43 changes: 31 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/Frame.ts
Expand Up @@ -183,7 +183,7 @@ class Frame {
if (isRole(params, true)) {
if (isFixed(params) || !isRole(params)) {
this._set(params, value);
} else {
} else {
const obj = toPropertyObject(value);

if (isObject(obj)) {
Expand Down Expand Up @@ -322,10 +322,12 @@ class Frame {
if (!length) {
return;
}
if (args.length === 1 && args[0] === TIMING_FUNCTION ) {
if (args.length === 1 && args[0] === TIMING_FUNCTION) {
properties[TIMING_FUNCTION] = getEasing(value);
} else {
properties[args[length - 1]] = isString(value) ? toPropertyObject(value) : value;
properties[args[length - 1]] = isString(value) && !isFixed(args)
? toPropertyObject(value)
: value;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/utils.ts
Expand Up @@ -9,7 +9,7 @@ import {
isArray, ANIMATION, ARRAY, OBJECT,
PROPERTY, STRING, NUMBER, IS_WINDOW, IObject, $, document, isObject, addEvent, removeEvent, isString,
} from "@daybrush/utils";
import { EasingType, EasingFunction } from "./types";
import { EasingType, EasingFunction, NameType } from "./types";
import { toPropertyObject } from "./utils/property";
import { bezier, steps } from "./easing";

Expand Down Expand Up @@ -97,7 +97,7 @@ export function getValueByNames(
}
return value;
}
export function isInProperties(roles: IObject<any>, args: string[], isCheckTrue?: boolean) {
export function isInProperties(roles: IObject<any>, args: NameType[], isCheckTrue?: boolean) {
const length = args.length;
let role: any = roles;

Expand All @@ -115,10 +115,10 @@ export function isInProperties(roles: IObject<any>, args: string[], isCheckTrue?
}
return true;
}
export function isRole(args: string[], isCheckTrue?: boolean) {
export function isRole(args: NameType[], isCheckTrue?: boolean) {
return isInProperties(ROLES, args, isCheckTrue);
}
export function isFixed(args: string[]) {
export function isFixed(args: NameType[]) {
return isInProperties(FIXED, args, true);
}

Expand Down
18 changes: 17 additions & 1 deletion test/unit/Frame.spec.ts
@@ -1,7 +1,8 @@
import Frame from "../../src/Frame";
import {setAlias} from "../../src/utils";
import {setAlias, setRole} from "../../src/utils";
import { EASE_IN_OUT } from "../../src/easing";
import { TIMING_FUNCTION, EASING_NAME } from "../../src/consts";
import Scene from "../../src";

describe("Frame Test", () => {
describe("test frame initialize", () => {
Expand Down Expand Up @@ -243,4 +244,19 @@ filter:brightness(90%) grayscale(40%);`.split("\n");
expect(css).to.have.string("scale(1,2) translateX(100px) translateY(200px) scale(3,4) translateX(100px)");
});
});
it ("should check text is text when setRole", () => {
// Given, When
setRole(["text"], false, true);
const frame = new Frame({
text: "#Scene.js #Moveable",
});

// restore
setRole(["text"], false, false);


// Then
expect(frame.get("text")).to.be.equals("#Scene.js #Moveable");
expect(frame.raw("text")).to.be.equals("#Scene.js #Moveable");
});
});

0 comments on commit 2752092

Please sign in to comment.