Skip to content

Commit 5624f9f

Browse files
authored
Rename configure to setConfig (#27)
* Rename configure to setConfig * Rename bridge function for iOS/Android, update tests * Update iOS and Android tests * Fix header text color on Android
1 parent daa7d74 commit 5624f9f

File tree

12 files changed

+49
-49
lines changed

12 files changed

+49
-49
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ session in the background and ahead of time.
266266
### Configuration
267267

268268
The SDK provides a way to customize the presented checkout experience through a
269-
`configuration` object in the Context Provider or a `configure` method on an
269+
`configuration` object in the Context Provider or a `setConfig` method on an
270270
instance of the `ShopifyCheckoutKit` class.
271271

272272
| Name | Required | Default | Description |

modules/react-native-shopify-checkout-kit/android/src/main/java/com/shopifycheckoutkit/ShopifyCheckoutKitModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ private ColorScheme getColors(ColorScheme colorScheme, ReadableMap config) {
216216
}
217217

218218
@ReactMethod
219-
public void configure(ReadableMap config) {
219+
public void setConfig(ReadableMap config) {
220220
Context context = getReactApplicationContext();
221221

222222
ShopifyCheckoutKit.configure(configuration -> {

modules/react-native-shopify-checkout-kit/ios/ShopifyCheckoutKit.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ @interface RCT_EXTERN_MODULE(RCTShopifyCheckoutKit, NSObject)
3232
RCT_EXTERN_METHOD(preload:(NSString *)checkoutURLString);
3333

3434
/// Set configuration for checkout
35-
RCT_EXTERN_METHOD(configure:(NSDictionary *)configuration);
35+
RCT_EXTERN_METHOD(setConfig:(NSDictionary *)configuration);
3636

3737
// Return configuration for checkout
3838
RCT_EXTERN_METHOD(getConfig: (RCTPromiseResolveBlock) resolve reject: (RCTPromiseRejectBlock) reject)

modules/react-native-shopify-checkout-kit/ios/ShopifyCheckoutKit.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class RCTShopifyCheckoutKit: RCTEventEmitter, CheckoutDelegate {
120120
}
121121
}
122122

123-
@objc func configure(_ configuration: [AnyHashable: Any]) {
123+
@objc func setConfig(_ configuration: [AnyHashable: Any]) {
124124
let colorConfig = configuration["colors"] as? [AnyHashable: Any]
125125
let iosConfig = colorConfig?["ios"] as? [String: String]
126126

modules/react-native-shopify-checkout-kit/src/context.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ type Maybe<T> = T | undefined;
3636
interface Context {
3737
addEventListener: AddEventListener;
3838
getConfig: () => Promise<Configuration | undefined>;
39+
setConfig: (config: Configuration) => void;
3940
removeEventListeners: RemoveEventListeners;
4041
preload: (checkoutUrl: string) => void;
4142
present: (checkoutUrl: string) => void;
42-
configure: (config: Configuration) => void;
4343
version: Maybe<string>;
4444
}
4545

@@ -48,7 +48,7 @@ const noop = () => undefined;
4848
const ShopifyCheckoutKitContext = React.createContext<Context>({
4949
addEventListener: noop,
5050
removeEventListeners: noop,
51-
configure: noop,
51+
setConfig: noop,
5252
getConfig: async () => undefined,
5353
preload: noop,
5454
present: noop,
@@ -92,8 +92,8 @@ export function ShopifyCheckoutKitProvider({
9292
}
9393
}, []);
9494

95-
const configure = useCallback((config: Configuration) => {
96-
instance.current?.configure(config);
95+
const setConfig = useCallback((config: Configuration) => {
96+
instance.current?.setConfig(config);
9797
}, []);
9898

9999
const getConfig = useCallback(async () => {
@@ -103,7 +103,7 @@ export function ShopifyCheckoutKitProvider({
103103
const context = useMemo((): Context => {
104104
return {
105105
addEventListener,
106-
configure,
106+
setConfig,
107107
getConfig,
108108
preload,
109109
present,
@@ -113,8 +113,8 @@ export function ShopifyCheckoutKitProvider({
113113
}, [
114114
addEventListener,
115115
removeEventListeners,
116-
configure,
117116
getConfig,
117+
setConfig,
118118
preload,
119119
present,
120120
]);

modules/react-native-shopify-checkout-kit/src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export interface ShopifyCheckoutKit {
150150
/**
151151
* Configure the checkout. See README.md for more details.
152152
*/
153-
configure(config: Configuration): void;
153+
setConfig(config: Configuration): void;
154154
/**
155155
* Return the current config for the checkout. See README.md for more details.
156156
*/

modules/react-native-shopify-checkout-kit/src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,14 @@ class ShopifyCheckoutKit implements ShopifyCheckout {
4949

5050
constructor(configuration?: Configuration) {
5151
if (configuration != null) {
52-
this.configure(configuration);
52+
this.setConfig(configuration);
5353
}
5454

5555
this.eventEmitter = new NativeEventEmitter(RNShopifyCheckoutKit);
5656
}
5757

5858
public readonly version: string = RNShopifyCheckoutKit.version;
5959

60-
public configure(configuration: Configuration): void {
61-
RNShopifyCheckoutKit.configure(configuration);
62-
}
63-
6460
public preload(checkoutUrl: string): void {
6561
RNShopifyCheckoutKit.preload(checkoutUrl);
6662
}
@@ -73,6 +69,10 @@ class ShopifyCheckoutKit implements ShopifyCheckout {
7369
return RNShopifyCheckoutKit.getConfig();
7470
}
7571

72+
public setConfig(configuration: Configuration): void {
73+
RNShopifyCheckoutKit.setConfig(configuration);
74+
}
75+
7676
public addEventListener(
7777
eventName: CheckoutEvent,
7878
callback: CheckoutEventCallback,

modules/react-native-shopify-checkout-kit/tests/index.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ jest.mock('react-native', () => {
2121

2222
const ShopifyCheckoutKit = {
2323
version: '0.7.0',
24-
configure: jest.fn(),
2524
preload: jest.fn(),
2625
present: jest.fn(),
2726
getConfig: jest.fn(async () => exampleConfig),
27+
setConfig: jest.fn(),
2828
addEventListener: jest.fn(),
2929
removeEventListeners: jest.fn(),
3030
};
@@ -39,31 +39,31 @@ jest.mock('react-native', () => {
3939

4040
describe('ShopifyCheckoutKit', () => {
4141
afterEach(() => {
42-
NativeModules.ShopifyCheckoutKit.configure.mockReset();
42+
NativeModules.ShopifyCheckoutKit.setConfig.mockReset();
4343
});
4444

4545
describe('instantiation', () => {
46-
it('calls `configure` with the specified config on instantiation', () => {
46+
it('calls `setConfig` with the specified config on instantiation', () => {
4747
new ShopifyCheckoutKit(config);
48-
expect(NativeModules.ShopifyCheckoutKit.configure).toHaveBeenCalledWith(
48+
expect(NativeModules.ShopifyCheckoutKit.setConfig).toHaveBeenCalledWith(
4949
config,
5050
);
5151
});
5252

53-
it('does not call `configure` if no config was specified on instantiation', () => {
53+
it('does not call `setConfig` if no config was specified on instantiation', () => {
5454
new ShopifyCheckoutKit();
55-
expect(NativeModules.ShopifyCheckoutKit.configure).not.toHaveBeenCalled();
55+
expect(NativeModules.ShopifyCheckoutKit.setConfig).not.toHaveBeenCalled();
5656
});
5757
});
5858

59-
describe('configure', () => {
60-
it('calls the `configure` on the Native Module', () => {
59+
describe('setConfig', () => {
60+
it('calls the `setConfig` on the Native Module', () => {
6161
const instance = new ShopifyCheckoutKit();
62-
instance.configure(config);
63-
expect(NativeModules.ShopifyCheckoutKit.configure).toHaveBeenCalledTimes(
62+
instance.setConfig(config);
63+
expect(NativeModules.ShopifyCheckoutKit.setConfig).toHaveBeenCalledTimes(
6464
1,
6565
);
66-
expect(NativeModules.ShopifyCheckoutKit.configure).toHaveBeenCalledWith(
66+
expect(NativeModules.ShopifyCheckoutKit.setConfig).toHaveBeenCalledWith(
6767
config,
6868
);
6969
});

sample/android/app/src/test/java/com/reactnative/ShopifyCheckoutKitModuleTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ public void callsPreloadWithCheckoutURL() {
6969
}
7070

7171
@Test
72-
public void configuresInternalConfig() {
72+
public void setsInternalConfig() {
7373
assertFalse(ShopifyCheckoutKitModule.checkoutConfig.getPreloading().getEnabled());
7474

7575
JavaOnlyMap updatedConfig = new JavaOnlyMap();
7676
updatedConfig.putBoolean("preloading", true);
7777
updatedConfig.putString("colorScheme", "dark");
78-
shopifyCheckoutKitModule.configure(updatedConfig);
78+
shopifyCheckoutKitModule.setConfig(updatedConfig);
7979

8080
boolean preloadingEnabled = ShopifyCheckoutKitModule.checkoutConfig.getPreloading().getEnabled();
8181
String colorScheme = ShopifyCheckoutKitModule.checkoutConfig.getColorScheme().getId();

sample/ios/ReactNativeTests/ShopifyCheckoutKitTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ShopifyCheckoutKitTests: XCTestCase {
7373
]
7474
]
7575

76-
shopifyCheckoutKit.configure(configuration)
76+
shopifyCheckoutKit.setConfig(configuration)
7777

7878
XCTAssertTrue(ShopifyCheckoutKit.configuration.preloading.enabled)
7979
XCTAssertEqual(ShopifyCheckoutKit.configuration.colorScheme, .dark)
@@ -86,7 +86,7 @@ class ShopifyCheckoutKitTests: XCTestCase {
8686
"preloading": false
8787
]
8888

89-
shopifyCheckoutKit.configure(configuration)
89+
shopifyCheckoutKit.setConfig(configuration)
9090

9191
XCTAssertFalse(ShopifyCheckoutKit.configuration.preloading.enabled)
9292
}
@@ -101,7 +101,7 @@ class ShopifyCheckoutKitTests: XCTestCase {
101101
]
102102

103103
let defaultColorFallback = UIColor(red: 0, green: 0, blue: 0, alpha: 1)
104-
shopifyCheckoutKit.configure(configuration)
104+
shopifyCheckoutKit.setConfig(configuration)
105105

106106
XCTAssertEqual(ShopifyCheckoutKit.configuration.spinnerColor, defaultColorFallback)
107107
}

0 commit comments

Comments
 (0)