Skip to content

Commit e9ee4d6

Browse files
author
Mohit
committed
refactor initializatin api
1 parent 1520219 commit e9ee4d6

10 files changed

Lines changed: 30 additions & 39 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const theme = {
3232
};
3333

3434
export type Theme = typeof theme;
35-
export const { StyleSheet, ThemeProvider, useTheme } = Sugar.init<Theme>(theme);
35+
export const { StyleSheet, ThemeProvider, useTheme } = Sugar<Theme>(theme);
3636

3737
export default StyleSheet;
3838
```

build/Main.d.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
/// <reference types="react" />
22
import Sugar from './Sugar';
3-
export default class Main {
4-
init<T>(theme: T): {
5-
StyleSheet: Sugar<T>;
6-
ThemeContext: import("react").Context<T>;
7-
ThemeProvider: import("react").ComponentType<{
8-
children: import("react").ReactNode;
9-
sugar?: Sugar<T> | undefined;
10-
}>;
11-
useTheme: () => T;
12-
withTheme: <P extends import("./type").ThemeProp<T>>(WrappedComponent: import("react").ComponentType<P>) => () => JSX.Element;
13-
};
14-
}
3+
export default function Main<T>(theme: T): {
4+
StyleSheet: Sugar<T>;
5+
ThemeContext: import("react").Context<T>;
6+
ThemeProvider: import("react").ComponentType<{
7+
children: import("react").ReactNode;
8+
sugar?: Sugar<T> | undefined;
9+
}>;
10+
useTheme: () => T;
11+
withTheme: <P extends import("./type").ThemeProp<T>>(WrappedComponent: import("react").ComponentType<P>) => () => JSX.Element;
12+
};

build/Main.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
Object.defineProperty(exports, "__esModule", { value: true });
33
const Sugar_1 = require("./Sugar");
44
const Provider_1 = require("./Provider");
5-
class Main {
6-
init(theme) {
7-
const StyleSheet = new Sugar_1.default(theme);
8-
const { ThemeContext, ThemeProvider, useTheme, withTheme } = Provider_1.themeCreator(StyleSheet, theme);
9-
return { StyleSheet, ThemeContext, ThemeProvider, useTheme, withTheme };
10-
}
5+
function Main(theme) {
6+
const StyleSheet = new Sugar_1.default(theme);
7+
const { ThemeContext, ThemeProvider, useTheme, withTheme } = Provider_1.themeCreator(StyleSheet, theme);
8+
return { StyleSheet, ThemeContext, ThemeProvider, useTheme, withTheme };
119
}
1210
exports.default = Main;

build/index.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ export * from './Constant';
22
export * from './Provider';
33
import Main from './Main';
44
export { Main as Sugar };
5-
declare const _default: Main;
6-
export default _default;
5+
export default Main;

build/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ __exportStar(require("./Constant"), exports);
1515
__exportStar(require("./Provider"), exports);
1616
const Main_1 = require("./Main");
1717
exports.Sugar = Main_1.default;
18-
exports.default = new Main_1.default();
18+
exports.default = Main_1.default;

example/style/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Sugar, { constants } from "react-native-sugar-style";
1+
import { Sugar, constants } from "react-native-sugar-style";
22

33
const commonTheme = {
44
...constants,
@@ -45,6 +45,6 @@ export const {
4545
ThemeContext,
4646
useTheme,
4747
withTheme
48-
} = Sugar.init<Theme>(lightTheme);
48+
} = Sugar<Theme>(lightTheme);
4949

5050
export default StyleSheet;

example/yarn.lock

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6801,10 +6801,7 @@ react-native-screens@~2.15.0:
68016801
integrity sha512-CagNf2APXkVoRlF3Mugr264FbKbrBg9eXUkqhIPVeZB8EsdS8XPrnt99yj/pzmT+yJMBY0dGrjXT8+68WYh6YQ==
68026802

68036803
react-native-sugar-style@./../:
6804-
version "0.0.9"
6805-
6806-
"react-native-sugar-style@file:./..":
6807-
version "0.0.9"
6804+
version "0.1.0"
68086805

68096806
react-native-unimodules@~0.12.0:
68106807
version "0.12.0"

lib/Main.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import Sugar from './Sugar';
22
import { themeCreator } from './Provider';
3-
export default class Main {
4-
init<T>(theme: T) {
5-
const StyleSheet = new Sugar<T>(theme);
6-
const { ThemeContext, ThemeProvider, useTheme, withTheme } = themeCreator(
7-
StyleSheet,
8-
theme
9-
);
10-
return { StyleSheet, ThemeContext, ThemeProvider, useTheme, withTheme };
11-
}
3+
4+
export default function Main<T>(theme: T) {
5+
const StyleSheet = new Sugar<T>(theme);
6+
const { ThemeContext, ThemeProvider, useTheme, withTheme } = themeCreator(
7+
StyleSheet,
8+
theme
9+
);
10+
return { StyleSheet, ThemeContext, ThemeProvider, useTheme, withTheme };
1211
}

lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ export * from './Constant';
22
export * from './Provider';
33
import Main from './Main';
44
export { Main as Sugar };
5-
export default new Main();
5+
export default Main;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-sugar-style",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "React Native Stylesheet alternative with theme support",
55
"author": "mohit23x",
66
"license": "MIT",

0 commit comments

Comments
 (0)