2015-01-30 01:10:49 +00:00
|
|
|
/**
|
2015-03-23 22:07:33 +00:00
|
|
|
* 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.
|
2015-01-30 01:10:49 +00:00
|
|
|
*
|
2016-03-24 22:12:36 +00:00
|
|
|
* @providesModule ReactNativePropRegistry
|
2015-03-25 02:34:12 +00:00
|
|
|
* @flow
|
2015-01-30 01:10:49 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-03-24 22:12:36 +00:00
|
|
|
var objects = {};
|
2015-01-30 01:10:49 +00:00
|
|
|
var uniqueID = 1;
|
2016-03-24 22:12:36 +00:00
|
|
|
var emptyObject = {};
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2016-03-24 22:12:36 +00:00
|
|
|
class ReactNativePropRegistry {
|
|
|
|
static register(object: Object): number {
|
2015-01-30 01:10:49 +00:00
|
|
|
var id = ++uniqueID;
|
|
|
|
if (__DEV__) {
|
2016-03-24 22:12:36 +00:00
|
|
|
Object.freeze(object);
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
2016-03-24 22:12:36 +00:00
|
|
|
objects[id] = object;
|
2015-01-30 01:10:49 +00:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2016-03-24 22:12:36 +00:00
|
|
|
static getByID(id: number): Object {
|
2015-01-30 01:10:49 +00:00
|
|
|
if (!id) {
|
|
|
|
// Used in the style={[condition && id]} pattern,
|
|
|
|
// we want it to be a no-op when the value is false or null
|
2016-03-24 22:12:36 +00:00
|
|
|
return emptyObject;
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
|
2016-03-24 22:12:36 +00:00
|
|
|
var object = objects[id];
|
|
|
|
if (!object) {
|
2015-01-30 01:10:49 +00:00
|
|
|
console.warn('Invalid style with id `' + id + '`. Skipping ...');
|
2016-03-24 22:12:36 +00:00
|
|
|
return emptyObject;
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
2016-03-24 22:12:36 +00:00
|
|
|
return object;
|
2015-01-30 01:10:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-24 22:12:36 +00:00
|
|
|
module.exports = ReactNativePropRegistry;
|