main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | module.exports = function (renderer, Comp, dynamicTemplate) {
|
---|
4 | if (process.env.NODE_ENV !== 'production') {
|
---|
5 | if (typeof dynamicTemplate !== 'function') {
|
---|
6 | var what;
|
---|
7 |
|
---|
8 | try {
|
---|
9 | what = JSON.stringify(dynamicTemplate);
|
---|
10 | } catch (error) {
|
---|
11 | what = String(dynamicTemplate);
|
---|
12 | }
|
---|
13 |
|
---|
14 | throw new TypeError('Dynamic CSS template must always be a function, ' + 'received: ' + what);
|
---|
15 | }
|
---|
16 | }
|
---|
17 |
|
---|
18 | var prototype = Comp.prototype;
|
---|
19 | var render_ = prototype.render;
|
---|
20 |
|
---|
21 | prototype.render = function () {
|
---|
22 | var element = render_.apply(this, arguments);
|
---|
23 | var props = element.props;
|
---|
24 | var dynamicClassName = '';
|
---|
25 |
|
---|
26 | if (dynamicTemplate) {
|
---|
27 | var dynamicStyles = dynamicTemplate(this.props);
|
---|
28 |
|
---|
29 | if (dynamicStyles) {
|
---|
30 | dynamicClassName = renderer.cache(dynamicStyles);
|
---|
31 | }
|
---|
32 | }
|
---|
33 |
|
---|
34 | if (!dynamicClassName) {
|
---|
35 | return element;
|
---|
36 | }
|
---|
37 |
|
---|
38 | var className = (props.className || '') + dynamicClassName;
|
---|
39 |
|
---|
40 | if (process.env.NODE_ENV !== 'production') {
|
---|
41 | return require('react').cloneElement(element, Object.assign({}, props, {
|
---|
42 | className: className
|
---|
43 | }), props.children);
|
---|
44 | }
|
---|
45 |
|
---|
46 | props.className = className;
|
---|
47 |
|
---|
48 | return element;
|
---|
49 | };
|
---|
50 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.