UNPKG

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