Updates from Tue 24 Mar

- [ReactNative] Open Source PushNotifications and move Badge Number methods and permission into it | Tadeu Zagallo
- [react-packager] Fix regression with transform errors | Amjad Masad
- Flowify TextStylePropTypes and fix a bug with unsupported props | Marshall Roch
- [ReactNative] Remove `arc build` instructions from require | Alex Kotliarskyi
- Flowify Library/Utilities/ | Marshall Roch
- [react-packager] Default to index.js from main if it's a dir | Amjad Masad
This commit is contained in:
Christopher Chedeau
2015-03-24 09:26:16 -07:00
parent c676e9dccc
commit 2d50d920fa
38 changed files with 837 additions and 245 deletions

View File

@@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule Dimensions
* @flow
*/
'use strict';
@@ -22,7 +23,7 @@ class Dimensions {
*
* @param {object} dims Simple string-keyed object of dimensions to set
*/
static set(dims) {
static set(dims: {[key:string]: any}): bool {
Object.assign(dimensions, dims);
return true;
}
@@ -40,7 +41,7 @@ class Dimensions {
* @param {string} dim Name of dimension as defined when calling `set`.
* @returns {Object?} Value for the dimension.
*/
static get(dim) {
static get(dim: string): Object {
invariant(dimensions[dim], 'No dimension set for key ' + dim);
return dimensions[dim];
}

View File

@@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule MessageQueue
* @flow
*/
'use strict';
var ErrorUtils = require('ErrorUtils');
@@ -18,6 +19,18 @@ var JSTimersExecution = require('JSTimersExecution');
var INTERNAL_ERROR = 'Error in MessageQueue implementation';
type ModulesConfig = {
[key:string]: {
moduleID: number;
methods: {[key:string]: {
methodID: number;
}};
}
}
type NameToID = {[key:string]: number}
type IDToName = {[key:number]: string}
/**
* So as not to confuse static build system.
*/
@@ -45,7 +58,11 @@ var jsCall = function(module, methodName, params) {
* efficient numeric IDs.
* @class MessageQueue
*/
var MessageQueue = function(remoteModulesConfig, localModulesConfig, customRequire) {
var MessageQueue = function(
remoteModulesConfig: ModulesConfig,
localModulesConfig: ModulesConfig,
customRequire: (id: string) => any
) {
this._requireFunc = customRequire || requireFunc;
this._initBookeeping();
this._initNamingMap(remoteModulesConfig, localModulesConfig);
@@ -128,7 +145,10 @@ var MessageQueueMixin = {
* @param {object} remoteModulesConfig Configuration of modules and their
* methods.
*/
_initNamingMap: function(remoteModulesConfig, localModulesConfig) {
_initNamingMap: function(
remoteModulesConfig: ModulesConfig,
localModulesConfig: ModulesConfig
) {
this._remoteModuleNameToModuleID = {};
this._remoteModuleIDToModuleName = {}; // Reverse
@@ -142,11 +162,11 @@ var MessageQueueMixin = {
this._localModuleNameToMethodIDToName = {}; // Reverse
function fillMappings(
modulesConfig,
moduleNameToModuleID,
moduleIDToModuleName,
moduleNameToMethodNameToID,
moduleNameToMethodIDToName
modulesConfig: ModulesConfig,
moduleNameToModuleID: NameToID,
moduleIDToModuleName: IDToName,
moduleNameToMethodNameToID: {[key:string]: NameToID},
moduleNameToMethodIDToName: {[key:string]: IDToName}
) {
for (var moduleName in modulesConfig) {
var moduleConfig = modulesConfig[moduleName];

View File

@@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule PixelRatio
* @flow
*/
'use strict';
@@ -52,7 +53,7 @@ class PixelRatio {
* - PixelRatio.get() === 3
* - iPhone 6 plus
*/
static get() {
static get(): number {
return Dimensions.get('window').scale;
}
}

View File

@@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule Platform
* @flow
*/
'use strict';

View File

@@ -1,93 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule PushNotificationIOS
*/
'use strict';
var NativeModules = require('NativeModules');
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
var RCTPushNotificationManager = NativeModules.PushNotificationManager;
if (RCTPushNotificationManager) {
var _initialNotification = RCTPushNotificationManager.initialNotification;
}
var _notifHandlers = {};
var DEVICE_NOTIF_EVENT = 'remoteNotificationReceived';
class PushNotificationIOS {
static addEventListener(type, handler) {
_notifHandlers[handler] = RCTDeviceEventEmitter.addListener(
DEVICE_NOTIF_EVENT,
(notifData) => {
handler(new PushNotificationIOS(notifData));
}
);
}
static removeEventListener(type, handler) {
if (!_notifHandlers[handler]) {
return;
}
_notifHandlers[handler].remove();
_notifHandlers[handler] = null;
}
static popInitialNotification() {
var initialNotification = _initialNotification &&
new PushNotificationIOS(_initialNotification);
_initialNotification = null;
return initialNotification;
}
constructor(nativeNotif) {
this._data = {};
// Extract data from Apple's `aps` dict as defined:
// https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html
Object.keys(nativeNotif).forEach((notifKey) => {
var notifVal = nativeNotif[notifKey];
if (notifKey === 'aps') {
this._alert = notifVal.alert;
this._sound = notifVal.sound;
this._badgeCount = notifVal.badge;
} else {
this._data[notifKey] = notifVal;
}
});
}
getMessage() {
// alias because "alert" is an ambiguous name
return this._alert;
}
getSound() {
return this._sound;
}
getAlert() {
return this._alert;
}
getBadgeCount() {
return this._badgeCount;
}
getData() {
return this._data;
}
}
module.exports = PushNotificationIOS;

View File

@@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule RCTLog
* @flow
*/
/* globals nativeLoggingHook */
'use strict';
@@ -31,7 +32,7 @@ class RCTLog {
logFn,
'Level "' + level + '" not one of ' + Object.keys(levelsMap)
);
if (typeof nativeLoggingHook === 'undefined') {
if (typeof global.nativeLoggingHook === 'undefined') {
// We already printed in xcode, so only log here if using a js debugger
console[logFn].apply(console, args);
}

View File

@@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule RCTRenderingPerf
* @flow
*/
'use strict';
@@ -15,6 +16,11 @@ var ReactPerf = require('ReactPerf');
var invariant = require('invariant');
type perfModule = {
start: () => void;
stop: () => void;
}
var perfModules = [];
var enabled = false;
@@ -58,7 +64,7 @@ var RCTRenderingPerf = {
perfModules.forEach((module) => module.stop());
},
register: function(module) {
register: function(module: perfModule) {
invariant(
typeof module.start === 'function',
'Perf module should have start() function'

View File

@@ -7,9 +7,13 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule TimerMixin
* @flow
*/
'use strict';
var setImmediate = require('setImmediate');
var clearImmediate = require('clearImmediate');
/**
* Using bare setTimeout, setInterval, setImmediate and
* requestAnimationFrame calls is very dangerous because if you forget to cancel
@@ -35,7 +39,10 @@
*/
var setter = function(setter, clearer, array) {
return function(callback, delta) {
return function(
callback: () => void,
delta: number
): number {
var id = setter(() => {
clearer.call(this, id);
callback.apply(this, arguments);
@@ -51,7 +58,7 @@
};
var clearer = function(clearer, array) {
return function(id) {
return function(id: number) {
if (this[array]) {
var index = this[array].indexOf(id);
if (index !== -1) {
@@ -75,8 +82,8 @@
var _setImmediate = setter(setImmediate, _clearImmediate, _immediates);
var _rafs = 'TimerMixin_rafs';
var _cancelAnimationFrame = clearer(cancelAnimationFrame, _rafs);
var _requestAnimationFrame = setter(requestAnimationFrame, _cancelAnimationFrame, _rafs);
var _cancelAnimationFrame = clearer(window.cancelAnimationFrame, _rafs);
var _requestAnimationFrame = setter(window.requestAnimationFrame, _cancelAnimationFrame, _rafs);
var TimerMixin = {
componentWillUnmount: function() {

View File

@@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule createStrictShapeTypeChecker
* @flow
*/
'use strict';
@@ -15,8 +16,10 @@ var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames');
var invariant = require('invariant');
var merge = require('merge');
function createStrictShapeTypeChecker(shapeTypes) {
function checkType(isRequired, props, propName, componentName, location) {
function createStrictShapeTypeChecker(
shapeTypes: {[key: string]: ReactPropsCheckType}
): ReactPropsChainableTypeChecker {
function checkType(isRequired, props, propName, componentName, location?) {
if (!props[propName]) {
if (isRequired) {
invariant(
@@ -29,7 +32,8 @@ function createStrictShapeTypeChecker(shapeTypes) {
}
var propValue = props[propName];
var propType = typeof propValue;
var locationName = ReactPropTypeLocationNames[location];
var locationName =
location && ReactPropTypeLocationNames[location] || '(unknown)';
if (propType !== 'object') {
invariant(
false,
@@ -57,11 +61,17 @@ function createStrictShapeTypeChecker(shapeTypes) {
error.message +
`\nBad object: ` + JSON.stringify(props[propName], null, ' ')
);
return error;
}
}
}
var chainedCheckType = checkType.bind(null, false);
function chainedCheckType(
props: {[key: string]: any},
propName: string,
componentName: string,
location?: string
): ?Error {
return checkType(false, props, propName, componentName, location);
}
chainedCheckType.isRequired = checkType.bind(null, true);
return chainedCheckType;
}

View File

@@ -7,8 +7,11 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule deepFreezeAndThrowOnMutationInDev
* @flow
*/
'use strict';
/**
* If your application is accepting different values for the same field over
* time and is doing a diff on them, you can either (1) create a copy or
@@ -26,7 +29,7 @@
* Freezing the object and adding the throw mechanism is expensive and will
* only be used in DEV.
*/
function deepFreezeAndThrowOnMutationInDev(object) {
function deepFreezeAndThrowOnMutationInDev(object: Object) {
if (__DEV__) {
if (typeof object !== 'object' ||
object === null ||

View File

@@ -7,9 +7,17 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule insetsDiffer
* @flow
*/
'use strict';
type Inset = {
top: ?number;
left: ?number;
right: ?number;
bottom: ?number;
}
var dummyInsets = {
top: undefined,
left: undefined,
@@ -17,7 +25,10 @@ var dummyInsets = {
bottom: undefined,
};
var insetsDiffer = function(one, two) {
var insetsDiffer = function(
one: ?Inset,
two: ?Inset
): bool {
one = one || dummyInsets;
two = two || dummyInsets;
return one !== two && (

View File

@@ -7,12 +7,18 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule pointsDiffer
* @flow
*/
'use strict';
type Point = {
x: ?number;
y: ?number;
}
var dummyPoint = {x: undefined, y: undefined};
var pointsDiffer = function(one, two) {
var pointsDiffer = function(one: ?Point, two: ?Point): bool {
one = one || dummyPoint;
two = two || dummyPoint;
return one !== two && (

View File

@@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule groupByEveryN
* @flow
*/
/**
@@ -26,7 +27,7 @@
*/
'use strict';
function groupByEveryN(array, n) {
function groupByEveryN<T>(array: Array<T>, n: number): Array<Array<?T>> {
var result = [];
var temp = [];

View File

@@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule logError
* @flow
*/
'use strict';

View File

@@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule mergeFast
* @flow
*/
'use strict';
@@ -19,7 +20,7 @@
* @return {object} Merging of two objects, including prototype
* inherited properties.
*/
var mergeFast = function(one, two) {
var mergeFast = function(one: Object, two: Object): Object {
var ret = {};
for (var keyOne in one) {
ret[keyOne] = one[keyOne];

View File

@@ -7,6 +7,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule mergeIntoFast
* @flow
*/
'use strict';
@@ -17,7 +18,7 @@
* @param {object} one Object to assign to.
* @param {object} two Object to assign from.
*/
var mergeIntoFast = function(one, two) {
var mergeIntoFast = function(one: Object, two: Object): void {
for (var keyTwo in two) {
one[keyTwo] = two[keyTwo];
}

View File

@@ -7,11 +7,14 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule nativeModulePrefixNormalizer
* @flow
*/
'use strict';
// Dirty hack to support old (RK) and new (RCT) native module name conventions
function nativeModulePrefixNormalizer(modules) {
function nativeModulePrefixNormalizer(
modules: {[key: string]: any}
): void {
Object.keys(modules).forEach((moduleName) => {
var strippedName = moduleName.replace(/^(RCT|RK)/, '');
if (modules['RCT' + strippedName] && modules['RK' + strippedName]) {

View File

@@ -7,11 +7,18 @@
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule truncate
* @flow
*/
'use strict';
var merge = require('merge');
type truncateOptions = {
breakOnWords: boolean;
minDelta: number;
elipsis: string;
}
var defaultOptions = {
breakOnWords: true,
minDelta: 10, // Prevents truncating a tiny bit off the end
@@ -19,7 +26,11 @@ var defaultOptions = {
};
// maxChars (including elipsis)
var truncate = function(str, maxChars, options) {
var truncate = function(
str: ?string,
maxChars: number,
options: truncateOptions
): ?string {
options = merge(defaultOptions, options);
if (str && str.length &&
str.length - options.minDelta + options.elipsis.length >= maxChars) {