Skip to content

Commit

Permalink
refactor: remove guards file
Browse files Browse the repository at this point in the history
  • Loading branch information
marklawlor committed May 1, 2023
1 parent f6771ef commit bd482db
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
3 changes: 1 addition & 2 deletions packages/expo-styling/src/css-to-rn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
Selector,
} from "lightningcss";

import { isRuntimeValue } from "../runtime/native/guards";
import { kebabToCamelCase } from "../runtime/native/utils";
import { isRuntimeValue, kebabToCamelCase } from "../runtime/native/utils";
import { ExtractedStyle, StyleSheetRegisterOptions } from "../types";
import { ParseDeclarationOptions, parseDeclaration } from "./parseDeclaration";

Expand Down
4 changes: 2 additions & 2 deletions packages/expo-styling/src/runtime/native/flattenStyle.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Style, StyleMeta, StyleProp } from "../../types";
import { testMediaQuery } from "./conditions";
import { rem, styleMetaMap, vh, vw } from "./globals";
import { isRuntimeValue } from "./guards";
import { Style, StyleMeta, StyleProp } from "../../types";
import { isRuntimeValue } from "./utils";

/**
* Reduce a StyleProp to a flat Style object.
Expand Down
17 changes: 0 additions & 17 deletions packages/expo-styling/src/runtime/native/guards.ts

This file was deleted.

18 changes: 17 additions & 1 deletion packages/expo-styling/src/runtime/native/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SignalLike } from "../../types";
import { RuntimeValue, SignalLike } from "../../types";

export function unwrap<T>(value: T | SignalLike<T>): T {
return value && typeof value === "object" && "get" in value
Expand All @@ -9,3 +9,19 @@ export function unwrap<T>(value: T | SignalLike<T>): T {
export function kebabToCamelCase(str: string) {
return str.replace(/-./g, (x) => x[1].toUpperCase());
}

export function isRuntimeValue(value: unknown): value is RuntimeValue {
if (!value) {
return false;
} else if (Array.isArray(value)) {
return value.some((v) => isRuntimeValue(v));
} else if (typeof value === "object") {
if ("type" in value && value.type === "runtime") {
return true;
} else {
return Object.values(value).some((v) => isRuntimeValue(v));
}
} else {
return false;
}
}

0 comments on commit bd482db

Please sign in to comment.