UNPKG

2.29 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2014-present, Facebook, Inc.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 *
8 */
9
10'use strict';
11
12// The Symbol used to tag the special React types. If there is no native Symbol
13// nor polyfill, then a plain number is used for performance.
14var REACT_COROUTINE_TYPE = typeof Symbol === 'function' && Symbol['for'] && Symbol['for']('react.coroutine') || 0xeac8;
15
16var REACT_YIELD_TYPE = typeof Symbol === 'function' && Symbol['for'] && Symbol['for']('react.yield') || 0xeac9;
17
18exports.createCoroutine = function (children, handler, props) {
19 var key = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
20
21 var coroutine = {
22 // This tag allow us to uniquely identify this as a React Coroutine
23 $$typeof: REACT_COROUTINE_TYPE,
24 key: key == null ? null : '' + key,
25 children: children,
26 handler: handler,
27 props: props
28 };
29
30 if (process.env.NODE_ENV !== 'production') {
31 // TODO: Add _store property for marking this as validated.
32 if (Object.freeze) {
33 Object.freeze(coroutine.props);
34 Object.freeze(coroutine);
35 }
36 }
37
38 return coroutine;
39};
40
41exports.createYield = function (props, continuation) {
42 var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
43
44 var yieldNode = {
45 // This tag allow us to uniquely identify this as a React Yield
46 $$typeof: REACT_YIELD_TYPE,
47 key: key == null ? null : '' + key,
48 props: props,
49 continuation: continuation
50 };
51
52 if (process.env.NODE_ENV !== 'production') {
53 // TODO: Add _store property for marking this as validated.
54 if (Object.freeze) {
55 Object.freeze(yieldNode.props);
56 Object.freeze(yieldNode);
57 }
58 }
59
60 return yieldNode;
61};
62
63/**
64 * Verifies the object is a coroutine object.
65 */
66exports.isCoroutine = function (object) {
67 return typeof object === 'object' && object !== null && object.$$typeof === REACT_COROUTINE_TYPE;
68};
69
70/**
71 * Verifies the object is a yield object.
72 */
73exports.isYield = function (object) {
74 return typeof object === 'object' && object !== null && object.$$typeof === REACT_YIELD_TYPE;
75};
76
77exports.REACT_YIELD_TYPE = REACT_YIELD_TYPE;
78exports.REACT_COROUTINE_TYPE = REACT_COROUTINE_TYPE;
\No newline at end of file