mirror of
https://github.com/status-im/react-native.git
synced 2025-01-17 04:50:59 +00:00
433fb336af
Summary:This avoids flattening styles in most common cases. It diffs against the nested arrays. The special case is when a property gets removed, it creates an object that stores the removed keys which then gets resolved using a second pass through the nested array. You can conceptually think of this algorithm as: 1) Diff and store changes as you go 2) If something was removed, flatten as necessary I also merged in another commit that renames the StyleSheetRegistry to ReactNativePropRegistry. There is nothing in here that makes it specific to styles anymore. That's just a decoupled view attribute configuration option. This registry can be used for any set of nested props, if we even want to keep this feature at all. Reviewed By: vjeux Differential Revision: D2492885 fb-gh-sync-id: c976ac28b7e63545132c36da0ee0c1c562e7c9e5 shipit-source-id: c976ac28b7e63545132c36da0ee0c1c562e7c9e5
45 lines
1.0 KiB
JavaScript
45 lines
1.0 KiB
JavaScript
/**
|
|
* 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 ReactNativePropRegistry
|
|
* @flow
|
|
*/
|
|
'use strict';
|
|
|
|
var objects = {};
|
|
var uniqueID = 1;
|
|
var emptyObject = {};
|
|
|
|
class ReactNativePropRegistry {
|
|
static register(object: Object): number {
|
|
var id = ++uniqueID;
|
|
if (__DEV__) {
|
|
Object.freeze(object);
|
|
}
|
|
objects[id] = object;
|
|
return id;
|
|
}
|
|
|
|
static getByID(id: number): Object {
|
|
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 emptyObject;
|
|
}
|
|
|
|
var object = objects[id];
|
|
if (!object) {
|
|
console.warn('Invalid style with id `' + id + '`. Skipping ...');
|
|
return emptyObject;
|
|
}
|
|
return object;
|
|
}
|
|
}
|
|
|
|
module.exports = ReactNativePropRegistry;
|