Skip to content

Commit 355a9ff

Browse files
author
Christopher Baker
committed
0.1.9
1 parent 8bac8a8 commit 355a9ff

File tree

2 files changed

+279
-0
lines changed

2 files changed

+279
-0
lines changed

dist/amd/can-react-component.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*can-react-component@0.1.8#can-react-component*/
2+
define([
3+
'require',
4+
'exports',
5+
'module',
6+
'react',
7+
'can-view-scope',
8+
'can-util/js/assign',
9+
'can-namespace'
10+
], function (require, exports, module) {
11+
var React = require('react');
12+
var Scope = require('can-view-scope');
13+
var assign = require('can-util/js/assign');
14+
var namespace = require('can-namespace');
15+
module.exports = namespace.reactComponent = function canReactComponent(displayName, CanComponent) {
16+
if (arguments.length === 1) {
17+
CanComponent = arguments[0];
18+
displayName = (CanComponent.shortName || 'CanComponent') + 'Wrapper';
19+
}
20+
function Wrapper() {
21+
React.Component.call(this);
22+
this.canComponent = null;
23+
this.createComponent = this.createComponent.bind(this);
24+
}
25+
Wrapper.displayName = displayName;
26+
Wrapper.prototype = Object.create(React.Component.prototype);
27+
assign(Wrapper.prototype, {
28+
constructor: Wrapper,
29+
createComponent: function (el) {
30+
if (this.canComponent) {
31+
this.canComponent = null;
32+
}
33+
if (el) {
34+
this.canComponent = new CanComponent(el, {
35+
subtemplate: null,
36+
templateType: 'react',
37+
parentNodeList: undefined,
38+
options: Scope.refsScope().add({}),
39+
scope: new Scope.Options({}),
40+
setupBindings: function (el, makeViewModel, initialViewModelData) {
41+
assign(initialViewModelData, this.props);
42+
makeViewModel(initialViewModelData);
43+
}.bind(this)
44+
});
45+
}
46+
},
47+
componentWillUpdate: function (props) {
48+
this.canComponent.viewModel.assign(props);
49+
},
50+
render: function () {
51+
return React.createElement(CanComponent.prototype.tag, { ref: this.createComponent });
52+
}
53+
});
54+
Object.defineProperty(Wrapper.prototype, 'viewModel', {
55+
enumerable: false,
56+
configurable: true,
57+
get: function () {
58+
return this.canComponent && this.canComponent.viewModel;
59+
}
60+
});
61+
try {
62+
Object.defineProperty(Wrapper, 'name', {
63+
writable: false,
64+
enumerable: false,
65+
configurable: true,
66+
value: displayName
67+
});
68+
} catch (e) {
69+
}
70+
return Wrapper;
71+
};
72+
});

dist/global/can-react-component.js

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
/*[global-shim-start]*/
2+
(function(exports, global, doEval) {
3+
// jshint ignore:line
4+
var origDefine = global.define;
5+
6+
var get = function(name) {
7+
var parts = name.split("."),
8+
cur = global,
9+
i;
10+
for (i = 0; i < parts.length; i++) {
11+
if (!cur) {
12+
break;
13+
}
14+
cur = cur[parts[i]];
15+
}
16+
return cur;
17+
};
18+
var set = function(name, val) {
19+
var parts = name.split("."),
20+
cur = global,
21+
i,
22+
part,
23+
next;
24+
for (i = 0; i < parts.length - 1; i++) {
25+
part = parts[i];
26+
next = cur[part];
27+
if (!next) {
28+
next = cur[part] = {};
29+
}
30+
cur = next;
31+
}
32+
part = parts[parts.length - 1];
33+
cur[part] = val;
34+
};
35+
var useDefault = function(mod) {
36+
if (!mod || !mod.__esModule) return false;
37+
var esProps = { __esModule: true, default: true };
38+
for (var p in mod) {
39+
if (!esProps[p]) return false;
40+
}
41+
return true;
42+
};
43+
44+
var hasCjsDependencies = function(deps) {
45+
return (
46+
deps[0] === "require" && deps[1] === "exports" && deps[2] === "module"
47+
);
48+
};
49+
50+
var modules =
51+
(global.define && global.define.modules) ||
52+
(global._define && global._define.modules) ||
53+
{};
54+
var ourDefine = (global.define = function(moduleName, deps, callback) {
55+
var module;
56+
if (typeof deps === "function") {
57+
callback = deps;
58+
deps = [];
59+
}
60+
var args = [],
61+
i;
62+
for (i = 0; i < deps.length; i++) {
63+
args.push(
64+
exports[deps[i]]
65+
? get(exports[deps[i]])
66+
: modules[deps[i]] || get(deps[i])
67+
);
68+
}
69+
// CJS has no dependencies but 3 callback arguments
70+
if (hasCjsDependencies(deps) || (!deps.length && callback.length)) {
71+
module = { exports: {} };
72+
args[0] = function(name) {
73+
return exports[name] ? get(exports[name]) : modules[name];
74+
};
75+
args[1] = module.exports;
76+
args[2] = module;
77+
} else if (!args[0] && deps[0] === "exports") {
78+
// Babel uses the exports and module object.
79+
module = { exports: {} };
80+
args[0] = module.exports;
81+
if (deps[1] === "module") {
82+
args[1] = module;
83+
}
84+
} else if (!args[0] && deps[0] === "module") {
85+
args[0] = { id: moduleName };
86+
}
87+
88+
global.define = origDefine;
89+
var result = callback ? callback.apply(null, args) : undefined;
90+
global.define = ourDefine;
91+
92+
// Favor CJS module.exports over the return value
93+
result = module && module.exports ? module.exports : result;
94+
modules[moduleName] = result;
95+
96+
// Set global exports
97+
var globalExport = exports[moduleName];
98+
if (globalExport && !get(globalExport)) {
99+
if (useDefault(result)) {
100+
result = result["default"];
101+
}
102+
set(globalExport, result);
103+
}
104+
});
105+
global.define.orig = origDefine;
106+
global.define.modules = modules;
107+
global.define.amd = true;
108+
ourDefine("@loader", [], function() {
109+
// shim for @@global-helpers
110+
var noop = function() {};
111+
return {
112+
get: function() {
113+
return { prepareGlobal: noop, retrieveGlobal: noop };
114+
},
115+
global: global,
116+
__exec: function(__load) {
117+
doEval(__load.source, global);
118+
}
119+
};
120+
});
121+
})(
122+
{},
123+
typeof self == "object" && self.Object == Object ? self : window,
124+
function(__$source__, __$global__) {
125+
// jshint ignore:line
126+
eval("(function() { " + __$source__ + " \n }).call(__$global__);");
127+
}
128+
);
129+
130+
/*can-react-component@0.1.8#can-react-component*/
131+
define('can-react-component', [
132+
'require',
133+
'exports',
134+
'module',
135+
'react',
136+
'can-view-scope',
137+
'can-util/js/assign/assign',
138+
'can-namespace'
139+
], function (require, exports, module) {
140+
var React = require('react');
141+
var Scope = require('can-view-scope');
142+
var assign = require('can-util/js/assign/assign');
143+
var namespace = require('can-namespace');
144+
module.exports = namespace.reactComponent = function canReactComponent(displayName, CanComponent) {
145+
if (arguments.length === 1) {
146+
CanComponent = arguments[0];
147+
displayName = (CanComponent.shortName || 'CanComponent') + 'Wrapper';
148+
}
149+
function Wrapper() {
150+
React.Component.call(this);
151+
this.canComponent = null;
152+
this.createComponent = this.createComponent.bind(this);
153+
}
154+
Wrapper.displayName = displayName;
155+
Wrapper.prototype = Object.create(React.Component.prototype);
156+
assign(Wrapper.prototype, {
157+
constructor: Wrapper,
158+
createComponent: function (el) {
159+
if (this.canComponent) {
160+
this.canComponent = null;
161+
}
162+
if (el) {
163+
this.canComponent = new CanComponent(el, {
164+
subtemplate: null,
165+
templateType: 'react',
166+
parentNodeList: undefined,
167+
options: Scope.refsScope().add({}),
168+
scope: new Scope.Options({}),
169+
setupBindings: function (el, makeViewModel, initialViewModelData) {
170+
assign(initialViewModelData, this.props);
171+
makeViewModel(initialViewModelData);
172+
}.bind(this)
173+
});
174+
}
175+
},
176+
componentWillUpdate: function (props) {
177+
this.canComponent.viewModel.assign(props);
178+
},
179+
render: function () {
180+
return React.createElement(CanComponent.prototype.tag, { ref: this.createComponent });
181+
}
182+
});
183+
Object.defineProperty(Wrapper.prototype, 'viewModel', {
184+
enumerable: false,
185+
configurable: true,
186+
get: function () {
187+
return this.canComponent && this.canComponent.viewModel;
188+
}
189+
});
190+
try {
191+
Object.defineProperty(Wrapper, 'name', {
192+
writable: false,
193+
enumerable: false,
194+
configurable: true,
195+
value: displayName
196+
});
197+
} catch (e) {
198+
}
199+
return Wrapper;
200+
};
201+
});
202+
/*[global-shim-end]*/
203+
(function(global) { // jshint ignore:line
204+
global._define = global.define;
205+
global.define = global.define.orig;
206+
}
207+
)(typeof self == "object" && self.Object == Object ? self : window);

0 commit comments

Comments
 (0)