Make UIManager prepackable

Reviewed By: sebmarkbage

Differential Revision: D7736403

fbshipit-source-id: 6154b76d9d948658394488fe4472d8b5bbcd3d9f
This commit is contained in:
Nikolai Tillmann 2018-04-27 19:09:34 -07:00 committed by Facebook Github Bot
parent 5fa9d78978
commit be32cbef00
1 changed files with 17 additions and 4 deletions

View File

@ -77,11 +77,24 @@ if (Platform.OS === 'ios') {
}
});
} else if (UIManager.ViewManagerNames) {
UIManager.ViewManagerNames.forEach(viewManagerName => {
defineLazyObjectProperty(UIManager, viewManagerName, {
get: () => UIManager.getConstantsForViewManager(viewManagerName),
// We want to add all the view managers to the UIManager.
// However, the way things are set up, the list of view managers is not known at compile time.
// As Prepack runs at compile it, it cannot process this loop.
// So we wrap it in a special __residual call, which basically tells Prepack to ignore it.
let residual = global.__residual ? global.__residual : (_, f, ...args) => f.apply(undefined, args);
residual("void", (UIManager, defineLazyObjectProperty) => {
UIManager.ViewManagerNames.forEach(viewManagerName => {
defineLazyObjectProperty(UIManager, viewManagerName, {
get: () => UIManager.getConstantsForViewManager(viewManagerName),
});
});
});
}, UIManager, defineLazyObjectProperty);
// As Prepack now no longer knows which properties exactly the UIManager has,
// we also tell Prepack that it has only partial knowledge of the UIManager,
// so that any accesses to unknown properties along the global code will fail
// when Prepack encounters them.
if (global.__makePartial) global.__makePartial(UIManager);
}
module.exports = UIManager;