Skip to content
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

[TM] Add spec for Settings #24879

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Libraries/Settings/NativeSettingsManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/

'use strict';

import type {TurboModule} from 'RCTExport';
import * as TurboModuleRegistry from 'TurboModuleRegistry';

export interface Spec extends TurboModule {
+getConstants: () => {|
settings: Object,
ericlewis marked this conversation as resolved.
Show resolved Hide resolved
|};
+setValues: (values: Object) => void;
+deleteValues: (values: Array<string>) => void;
}

export default TurboModuleRegistry.getEnforcing<Spec>('SettingsManager');
7 changes: 3 additions & 4 deletions Libraries/Settings/Settings.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,22 @@
'use strict';

const RCTDeviceEventEmitter = require('../EventEmitter/RCTDeviceEventEmitter');
const RCTSettingsManager = require('../BatchedBridge/NativeModules')
.SettingsManager;
import NativeSettingsManager from './NativeSettingsManager';

const invariant = require('invariant');

const subscriptions: Array<{keys: Array<string>, callback: ?Function}> = [];

const Settings = {
_settings: RCTSettingsManager && RCTSettingsManager.settings,
_settings: NativeSettingsManager && NativeSettingsManager.settings,
ericlewis marked this conversation as resolved.
Show resolved Hide resolved

get(key: string): mixed {
return this._settings[key];
},

set(settings: Object) {
this._settings = Object.assign(this._settings, settings);
RCTSettingsManager.setValues(settings);
NativeSettingsManager.setValues(settings);
},

watchKeys(keys: string | Array<string>, callback: Function): number {
Expand Down