Added LinkedInput addon.
jim committed
Dec 22, 2015 at 15:27 UTC
0acdb7b56ac62d81f79feb309e7beaef8140aeb9
2 files changed
+70
src/addons/link/LinkedInput.js
new
+28
@@ -0,0 +1,28 @@
1
+/**
2
+ * Copyright 2013-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
+ * @providesModule LinkedInput
10
+ */
11
+
12
+'use strict';
13
+
14
+var React = require('React');
15
+var LinkedValueUtils = require('LinkedValueUtils');
16
+
17
+class LinkedInput extends React.Component {
18
+ render() {
19
+ var newProps = Object.assign({}, this.props);
20
+ newProps.value = LinkedValueUtils.getValue(this.props);
21
+ newProps.checked = LinkedValueUtils.getChecked(this.props);
22
+ delete newProps.valueLink;
23
+ delete newProps.checkedLink;
24
+ return <input {...newProps} />;
25
+ }
26
+}
27
+
28
+module.exports = LinkedInput;
src/addons/link/__tests__/LinkedInput-test.js
new
+42
@@ -0,0 +1,42 @@
1
+/**
2
+ * Copyright 2013-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
+ * @emails react-core
10
+ */
11
+
12
+'use strict';
13
+
14
+
15
+describe('LinkedStateMixin', function() {
16
+ var LinkedInput;
17
+ var React;
18
+ var ReactDOM;
19
+
20
+ beforeEach(function() {
21
+ LinkedInput = require('LinkedInput');
22
+ React = require('React');
23
+ ReactDOM = require('ReactDOM');
24
+ });
25
+
26
+ it('should basically work', function() {
27
+ var container = document.createElement('div');
28
+ var component = ReactDOM.render(<LinkedInput value="foo" onChange={function() {}} />, container);
29
+ var input = ReactDOM.findDOMNode(component);
30
+ expect(input.value).toBe('foo');
31
+ ReactDOM.render(<LinkedInput valueLink={{value: 'boo', requestChange: function() {}}} />, container);
32
+ expect(input.value).toBe('boo');
33
+ });
34
+
35
+ it('should throw', function() {
36
+ var container = document.createElement('div');
37
+ var element = <LinkedInput value="foo" valueLink={{value: 'boo', requestChange: function() {}}} />;
38
+ expect(function() {
39
+ ReactDOM.render(element, container);
40
+ }).toThrow();
41
+ });
42
+});