forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add react-call-return package (facebook#11364)
- Loading branch information
1 parent
f81fdd8
commit aaada92
Showing
20 changed files
with
341 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# react-call-return | ||
|
||
This is an experimental package for multi-pass rendering in React. | ||
|
||
**Its API is not as stable as that of React, React Native, or React DOM, and does not follow the common versioning scheme.** | ||
|
||
**Use it at your own risk.** | ||
|
||
# API | ||
|
||
See the test case in `src/__tests__/ReactCallReturn.js` for an example. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = require('./src/ReactCallReturn'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/react-call-return.production.min.js'); | ||
} else { | ||
module.exports = require('./cjs/react-call-return.development.js'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "react-call-return", | ||
"description": "Experimental APIs for multi-pass rendering in React.", | ||
"version": "0.1.0", | ||
"repository": "facebook/react", | ||
"dependencies": { | ||
"fbjs": "^0.8.16", | ||
"object-assign": "^4.1.1" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type {ReactCall, ReactNodeList, ReactReturn} from 'shared/ReactTypes'; | ||
|
||
// The Symbol used to tag the special React types. If there is no native Symbol | ||
// nor polyfill, then a plain number is used for performance. | ||
var REACT_CALL_TYPE; | ||
var REACT_RETURN_TYPE; | ||
if (typeof Symbol === 'function' && Symbol.for) { | ||
REACT_CALL_TYPE = Symbol.for('react.call'); | ||
REACT_RETURN_TYPE = Symbol.for('react.return'); | ||
} else { | ||
REACT_CALL_TYPE = 0xeac8; | ||
REACT_RETURN_TYPE = 0xeac9; | ||
} | ||
|
||
type CallHandler<T> = (props: T, returns: Array<mixed>) => ReactNodeList; | ||
|
||
exports.unstable_createCall = function<T>( | ||
children: mixed, | ||
handler: CallHandler<T>, | ||
props: T, | ||
key: ?string = null, | ||
): ReactCall { | ||
var call = { | ||
// This tag allow us to uniquely identify this as a React Call | ||
$$typeof: REACT_CALL_TYPE, | ||
key: key == null ? null : '' + key, | ||
children: children, | ||
handler: handler, | ||
props: props, | ||
}; | ||
|
||
if (__DEV__) { | ||
// TODO: Add _store property for marking this as validated. | ||
if (Object.freeze) { | ||
Object.freeze(call.props); | ||
Object.freeze(call); | ||
} | ||
} | ||
|
||
return call; | ||
}; | ||
|
||
exports.unstable_createReturn = function(value: mixed): ReactReturn { | ||
var returnNode = { | ||
// This tag allow us to uniquely identify this as a React Return | ||
$$typeof: REACT_RETURN_TYPE, | ||
value: value, | ||
}; | ||
|
||
if (__DEV__) { | ||
// TODO: Add _store property for marking this as validated. | ||
if (Object.freeze) { | ||
Object.freeze(returnNode); | ||
} | ||
} | ||
|
||
return returnNode; | ||
}; | ||
|
||
/** | ||
* Verifies the object is a call object. | ||
*/ | ||
exports.unstable_isCall = function(object: mixed): boolean { | ||
return ( | ||
typeof object === 'object' && | ||
object !== null && | ||
object.$$typeof === REACT_CALL_TYPE | ||
); | ||
}; | ||
|
||
/** | ||
* Verifies the object is a return object. | ||
*/ | ||
exports.unstable_isReturn = function(object: mixed): boolean { | ||
return ( | ||
typeof object === 'object' && | ||
object !== null && | ||
object.$$typeof === REACT_RETURN_TYPE | ||
); | ||
}; | ||
|
||
exports.unstable_REACT_RETURN_TYPE = REACT_RETURN_TYPE; | ||
exports.unstable_REACT_CALL_TYPE = REACT_CALL_TYPE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.