From c55e3649dd317f14cfcce0ea18d9aa142de2c485 Mon Sep 17 00:00:00 2001 From: Igor Avramovic Date: Thu, 2 Jun 2016 17:33:28 -0700 Subject: [PATCH] Lazy load platform specific code Differential Revision: D3369528 fbshipit-source-id: 0fbc63fbac5e96468598fb3d0a86c6b20f96f39d --- Libraries/Utilities/Platform.android.js | 9 ++++++++- Libraries/Utilities/Platform.ios.js | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Libraries/Utilities/Platform.android.js b/Libraries/Utilities/Platform.android.js index 86861e4c7..c9ba2c0bc 100644 --- a/Libraries/Utilities/Platform.android.js +++ b/Libraries/Utilities/Platform.android.js @@ -12,10 +12,17 @@ 'use strict'; -var Platform = { +const Platform = { OS: 'android', get Version() { return require('NativeModules').AndroidConstants.Version; }, select: (obj: Object) => obj.android, + lazySelect(obj: ?Object): ?Object { + if (!obj || !obj.android) { + return null; + } + + return obj.android(); + }, }; module.exports = Platform; diff --git a/Libraries/Utilities/Platform.ios.js b/Libraries/Utilities/Platform.ios.js index 070bd2874..99eb5d1c1 100644 --- a/Libraries/Utilities/Platform.ios.js +++ b/Libraries/Utilities/Platform.ios.js @@ -12,9 +12,16 @@ 'use strict'; -var Platform = { +const Platform = { OS: 'ios', select: (obj: Object) => obj.ios, + lazySelect(obj: ?Object): ?Object { + if (!obj || !obj.ios) { + return null; + } + + return obj.ios(); + }, }; module.exports = Platform;