2016-03-31 05:35:46 +08:00
|
|
|
/**
|
2017-09-25 04:48:13 +08:00
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
2016-03-31 05:35:46 +08:00
|
|
|
*
|
2017-09-25 04:48:13 +08:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-03-31 05:35:46 +08:00
|
|
|
*/
|
|
|
|
|
|
2017-11-03 03:50:03 +08:00
|
|
|
import invariant from 'fbjs/lib/invariant';
|
2016-03-31 05:35:46 +08:00
|
|
|
|
|
|
|
|
var instanceCache = {};
|
2017-01-20 13:56:15 +08:00
|
|
|
var instanceProps = {};
|
2016-03-31 05:35:46 +08:00
|
|
|
|
2017-11-05 19:58:36 +08:00
|
|
|
export function precacheFiberNode(hostInst, tag) {
|
2016-12-08 10:15:13 +08:00
|
|
|
instanceCache[tag] = hostInst;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-05 19:58:36 +08:00
|
|
|
export function uncacheFiberNode(tag) {
|
2016-12-08 10:15:13 +08:00
|
|
|
delete instanceCache[tag];
|
2017-02-23 02:21:24 +08:00
|
|
|
delete instanceProps[tag];
|
2016-12-08 10:15:13 +08:00
|
|
|
}
|
|
|
|
|
|
2016-03-31 05:35:46 +08:00
|
|
|
function getInstanceFromTag(tag) {
|
|
|
|
|
return instanceCache[tag] || null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getTagFromInstance(inst) {
|
2017-08-24 06:53:55 +08:00
|
|
|
var tag = inst.stateNode._nativeTag;
|
2016-12-08 10:15:13 +08:00
|
|
|
invariant(tag, 'All native instances should have a tag.');
|
|
|
|
|
return tag;
|
2016-03-31 05:35:46 +08:00
|
|
|
}
|
|
|
|
|
|
2017-11-05 19:58:36 +08:00
|
|
|
export {
|
|
|
|
|
getInstanceFromTag as getClosestInstanceFromNode,
|
|
|
|
|
getInstanceFromTag as getInstanceFromNode,
|
|
|
|
|
getTagFromInstance as getNodeFromInstance,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function getFiberCurrentPropsFromNode(stateNode) {
|
2017-02-09 15:28:56 +08:00
|
|
|
return instanceProps[stateNode._nativeTag] || null;
|
2017-01-20 13:56:15 +08:00
|
|
|
}
|
|
|
|
|
|
2017-11-05 19:58:36 +08:00
|
|
|
export function updateFiberProps(tag, props) {
|
2017-01-20 13:56:15 +08:00
|
|
|
instanceProps[tag] = props;
|
|
|
|
|
}
|