Skip to content

Commit aa4685d

Browse files
committed
Replace Style.(flatten|concat|combine) by (fromArray|fromList|merge)
1 parent 1f313c2 commit aa4685d

3 files changed

Lines changed: 58 additions & 35 deletions

File tree

‎lib/js/src/style.js‎

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

‎src/style.re‎

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,11 @@ let encode_deg_animated =
6666
| Deg(value) => Internals.Encoder.string(value)
6767
| Animated(value) => Internals.Encoder.animatedValue(value);
6868

69-
external flatten: array(t) => t = "%identity";
70-
7169
external to_style: Js.Dict.t(Js.Json.t) => t = "%identity";
7270

7371
external style_to_dict: t => Js.Dict.t(Js.Json.t) = "%identity";
7472

75-
external array_to_style: array(t) => t = "%identity";
76-
77-
let combine = (a, b) => {
78-
let entries =
79-
Array.append(
80-
Js.Dict.entries(style_to_dict(a)),
81-
Js.Dict.entries(style_to_dict(b)),
82-
);
83-
Js.Dict.fromArray(entries) |> to_style;
84-
};
85-
86-
let concat = styles => array_to_style(Array.of_list(styles));
73+
external arrayOfStyle: array(t) => t = "%identity";
8774

8875
let floatStyle = (key, value) => (key, Internals.Encoder.float(value));
8976

@@ -94,14 +81,28 @@ let objectStyle = (key, value) => (key, Internals.Encoder.object_(value));
9481
let arrayStyle = (key, value) => (key, Internals.Encoder.array(value));
9582

9683
let style = sarr => sarr |> Js.Dict.fromList |> to_style;
84+
let emptyStyle = Js.Dict.empty()->to_style;
9785

98-
let emptyStyle = style([]);
99-
100-
let combineOptional = (s, so) =>
101-
so->Belt.Option.map(so => s->combine(so))->Belt.Option.getWithDefault(s);
102-
86+
external fromArray: array(t) => t = "%identity";
87+
let fromList = styles => styles->Belt.List.toArray->arrayOfStyle;
88+
let merge = (a, b) => {
89+
let entries =
90+
Array.append(
91+
Js.Dict.entries(style_to_dict(a)),
92+
Js.Dict.entries(style_to_dict(b)),
93+
);
94+
Js.Dict.fromArray(entries) |> to_style;
95+
};
96+
let mergeOptional = (s, so) =>
97+
so->Belt.Option.map(so => s->merge(so))->Belt.Option.getWithDefault(s);
10398
let optional = s => s->Belt.Option.getWithDefault(emptyStyle);
10499

100+
/* deprecated */
101+
let flatten = fromArray;
102+
let concat = fromList;
103+
let combine = merge;
104+
let combineOptional = mergeOptional;
105+
105106
/***
106107
* Layout Props
107108
*/

‎src/style.rei‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,22 @@ type string_interpolated =
2323
type deg_animated('a) =
2424
| Deg(string)
2525
| Animated(AnimatedRe.value('a));
26-
external flatten: array(t) => t = "%identity";
26+
27+
let style: list(styleElement) => t;
28+
external fromArray: array(t) => t = "%identity";
29+
let fromList: list(t) => t;
30+
let merge: (t, t) => t;
31+
let mergeOptional: (t, option(t)) => t;
32+
let optional: option(t) => t;
33+
34+
[@deprecated "use Style.fromArray([|t|]) instead"]
35+
let flatten: array(t) => t;
36+
[@deprecated "use Style.merge(t, t) instead"]
2737
let combine: (t, t) => t;
38+
[@deprecated "use Style.fromList([t]) instead"]
2839
let concat: list(t) => t;
29-
let style: list(styleElement) => t;
30-
let emptyStyle: t;
40+
[@deprecated "use Style.mergeOptional(t, option(t)) instead"]
3141
let combineOptional: (t, option(t)) => t;
32-
let optional: (option(t)) => t;
3342

3443
type alignContent =
3544
| FlexStart

0 commit comments

Comments
 (0)