2015-01-29 17:10:49 -08:00
|
|
|
/**
|
2015-03-23 15:07:33 -07: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-29 17:10:49 -08:00
|
|
|
*
|
|
|
|
* @providesModule StyleSheetRegistry
|
2015-03-24 19:34:12 -07:00
|
|
|
* @flow
|
2015-01-29 17:10:49 -08:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var styles = {};
|
|
|
|
var uniqueID = 1;
|
|
|
|
var emptyStyle = {};
|
|
|
|
|
|
|
|
class StyleSheetRegistry {
|
2015-03-24 19:34:12 -07:00
|
|
|
static registerStyle(style: Object): number {
|
2015-01-29 17:10:49 -08:00
|
|
|
var id = ++uniqueID;
|
|
|
|
if (__DEV__) {
|
|
|
|
Object.freeze(style);
|
|
|
|
}
|
|
|
|
styles[id] = style;
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2015-03-24 19:34:12 -07:00
|
|
|
static getStyleByID(id: number): Object {
|
2015-01-29 17:10:49 -08: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
|
|
|
|
return emptyStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
var style = styles[id];
|
|
|
|
if (!style) {
|
|
|
|
console.warn('Invalid style with id `' + id + '`. Skipping ...');
|
|
|
|
return emptyStyle;
|
|
|
|
}
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = StyleSheetRegistry;
|