react-native-molecules 0.5.0-beta.4 → 0.5.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,48 @@
1
+ import { useEffect, useMemo } from 'react';
2
+
3
+ import useLatest from './useLatest';
4
+
5
+ const map = new Map();
6
+
7
+ export const whatHasUpdatedFactory = <T extends Record<string, unknown>>(
8
+ name: string,
9
+ prevObject: T,
10
+ { debug = false, useCached = false } = {},
11
+ ) => {
12
+ const getPrev = () => {
13
+ if (!map.has(name)) map.set(name, prevObject);
14
+ return useCached ? map.get(name) : prevObject;
15
+ };
16
+
17
+ const setPrev = (value: T) => {
18
+ if (useCached) map.set(name, value);
19
+ else prevObject = value;
20
+ };
21
+
22
+ return (nextObject: T) => {
23
+ const old = getPrev();
24
+ const changes = Object.keys({ ...nextObject, ...old }).reduce((all, key) => {
25
+ const newValue = nextObject?.[key];
26
+ const oldValue = old[key];
27
+ if (oldValue === newValue) return all;
28
+ return { ...all, [key]: { newValue, oldValue } };
29
+ }, {});
30
+
31
+ setPrev(nextObject);
32
+
33
+ if (!debug && !Object.keys(changes).length) return;
34
+ // eslint-disable-next-line no-console
35
+ console.log('🚨🕵️ UPDATED', name, changes);
36
+ };
37
+ };
38
+
39
+ export const useWhatHasUpdated = (name: string, props: Record<string, any>) => {
40
+ const argRef = useLatest({ name, props });
41
+ const checkFunc = useMemo(
42
+ () => whatHasUpdatedFactory(argRef.current.name, argRef.current.props),
43
+ [argRef],
44
+ );
45
+ useEffect(() => {
46
+ checkFunc(props);
47
+ });
48
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-molecules",
3
- "version": "0.5.0-beta.4",
3
+ "version": "0.5.0-beta.5",
4
4
  "author": "Thet Aung <thetaung.dev@gmail.com>",
5
5
  "license": "MIT",
6
6
  "main": "index.ts",
package/styles/shadow.ts CHANGED
@@ -8,7 +8,8 @@ export const inputRange: MD3Elevation[] = [0, 1, 2, 3, 4, 5];
8
8
  export const shadowHeight = [0, 1, 2, 4, 6, 8];
9
9
  export const shadowRadius = [0, 3, 6, 8, 10, 12];
10
10
 
11
- export default function shadow(elevation: number) {
11
+ export default function shadow(_elevation: number) {
12
+ const elevation = typeof _elevation === 'number' ? (_elevation > 5 ? 5 : _elevation) : 0;
12
13
  return {
13
14
  shadowColor: MD3_SHADOW_COLOR,
14
15
  shadowOpacity: elevation ? MD3_SHADOW_OPACITY : 0,