-
Notifications
You must be signed in to change notification settings - Fork 16
feat(Runtime): Add Rollout Percentage functionality #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
eeeb4e0
5d27109
1bd6756
1ba36c3
63e6c01
512609e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.microsoft.codepush.react; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.facebook.react.bridge.Promise; | ||
|
||
public class RolloutStorageModule extends ReactContextBaseJavaModule { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The SettingsManager already handles interactions with SharedPreference. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't really want to touch the other modules, hence, added this module, but lmk, if I should instead stick to using SettingsManager? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, no. I was just curious about the reason. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay great! |
||
|
||
private final SharedPreferences prefs; | ||
|
||
public RolloutStorageModule(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
prefs = reactContext.getSharedPreferences("CodePushPrefs", Context.MODE_PRIVATE); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "RolloutStorage"; | ||
} | ||
|
||
@ReactMethod | ||
public void getItem(String key, Promise promise) { | ||
promise.resolve(prefs.getString(key, null)); | ||
} | ||
|
||
@ReactMethod | ||
public void setItem(String key, String value) { | ||
prefs.edit().putString(key, value).apply(); | ||
} | ||
|
||
@ReactMethod | ||
public void removeItem(String key) { | ||
prefs.edit().remove(key).apply(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#import <React/RCTBridgeModule.h> | ||
|
||
@interface RolloutStorage : NSObject <RCTBridgeModule> | ||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#import "RolloutStorage.h" | ||
|
||
@implementation RolloutStorage | ||
|
||
RCT_EXPORT_MODULE(); | ||
|
||
RCT_EXPORT_METHOD(setItem:(NSString *)key value:(NSString *)value) { | ||
[[NSUserDefaults standardUserDefaults] setObject:value forKey:key]; | ||
} | ||
|
||
RCT_EXPORT_METHOD(getItem:(NSString *)key | ||
resolver:(RCTPromiseResolveBlock)resolve | ||
rejecter:(RCTPromiseRejectBlock)reject) { | ||
NSString *value = [[NSUserDefaults standardUserDefaults] stringForKey:key]; | ||
resolve(value); | ||
} | ||
|
||
RCT_EXPORT_METHOD(removeItem:(NSString *)key) { | ||
[[NSUserDefaults standardUserDefaults] removeObjectForKey:key]; | ||
} | ||
|
||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems possible to implement without adding
ROLLOUT_CACHE_KEY
..I will take a look while refactoring the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay pls do share once you refactor.