All files / react-native-web/src/exports/StyleSheet ReactNativePropRegistry.js

85% Statements 17/20
50% Branches 3/6
100% Functions 3/3
84.21% Lines 16/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44                    22x 22x 22x 22x   643x       239x 239x 239x   239x 239x 239x       404x         404x 404x 404x       404x      
/**
 * Copyright (c) Nicolas Gallagher.
 * 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
 */
 
const emptyObject = {};
const objects = {};
const prefix = 'r';
let uniqueID = 1;
 
const createKey = (id) => `${prefix}-${id}`;
 
export default class ReactNativePropRegistry {
  static register(object: Object): number {
    const id = uniqueID++;
    Eif (process.env.NODE_ENV !== 'production') {
      Object.freeze(object);
    }
    const key = createKey(id);
    objects[key] = object;
    return id;
  }
 
  static getByID(id: number): Object {
    Iif (!id) {
      // Used in the style={[condition && id]} pattern,
      // we want it to be a no-op when the value is false or null
      return emptyObject;
    }
    const key = createKey(id);
    const object = objects[key];
    Iif (!object) {
      console.warn('Invalid style with id `' + id + '`. Skipping ...');
      return emptyObject;
    }
    return object;
  }
}