main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.6 KB
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var addonCache = require('./cache').addon;
|
---|
| 4 |
|
---|
| 5 | exports.addon = function (renderer) {
|
---|
| 6 | if (!renderer.cache) {
|
---|
| 7 | addonCache(renderer);
|
---|
| 8 | }
|
---|
| 9 |
|
---|
| 10 | if (process.env.NODE_ENV !== 'production') {
|
---|
| 11 | require('./__dev__/warnOnMissingDependencies')('jsx', renderer, ['rule', 'cache']);
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | renderer.jsx = function (fn, styles, block) {
|
---|
| 15 | var className;
|
---|
| 16 | var isElement = typeof fn === 'string';
|
---|
| 17 |
|
---|
| 18 | // In dev mode emit CSS immediately so correct sourcemaps can be generated.
|
---|
| 19 | if (process.env.NODE_ENV !== 'production') {
|
---|
| 20 | className = renderer.rule(styles, block);
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | var Component = function (props) {
|
---|
| 24 | if (!className) {
|
---|
| 25 | className = renderer.rule(styles, block);
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | var copy = props;
|
---|
| 29 | var $as = copy.$as;
|
---|
| 30 | var $ref = copy.$ref;
|
---|
| 31 |
|
---|
| 32 | if (process.env.NODE_ENV !== 'production') {
|
---|
| 33 | copy = renderer.assign({}, props);
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | var dynamicClassName = renderer.cache(props.css);
|
---|
| 37 | delete copy.css;
|
---|
| 38 | delete copy.$as;
|
---|
| 39 |
|
---|
| 40 | if (isElement || $as) {
|
---|
| 41 | delete copy.$ref;
|
---|
| 42 | copy.ref = $ref;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | copy.className = (props.className || '') + className + dynamicClassName;
|
---|
| 46 |
|
---|
| 47 | return (isElement || $as)
|
---|
| 48 | ? renderer.h($as || fn, copy)
|
---|
| 49 | : fn(copy);
|
---|
| 50 | };
|
---|
| 51 |
|
---|
| 52 | if (process.env.NODE_ENV !== 'production') {
|
---|
| 53 | if (block) {
|
---|
| 54 | Component.displayName = 'jsx(' + block + ')';
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | return Component;
|
---|
| 59 | };
|
---|
| 60 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.