forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Copyright 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule LinkedInput | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var React = require('React'); | ||
var LinkedValueUtils = require('LinkedValueUtils'); | ||
|
||
class LinkedInput extends React.Component { | ||
render() { | ||
var newProps = Object.assign({}, this.props); | ||
newProps.value = LinkedValueUtils.getValue(this.props); | ||
newProps.checked = LinkedValueUtils.getChecked(this.props); | ||
delete newProps.valueLink; | ||
delete newProps.checkedLink; | ||
return <input {...newProps} />; | ||
} | ||
} | ||
|
||
module.exports = LinkedInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @emails react-core | ||
*/ | ||
|
||
'use strict'; | ||
|
||
|
||
describe('LinkedStateMixin', function() { | ||
var LinkedInput; | ||
var React; | ||
var ReactDOM; | ||
|
||
beforeEach(function() { | ||
LinkedInput = require('LinkedInput'); | ||
React = require('React'); | ||
ReactDOM = require('ReactDOM'); | ||
}); | ||
|
||
it('should basically work', function() { | ||
var container = document.createElement('div'); | ||
var component = ReactDOM.render(<LinkedInput value="foo" onChange={function() {}} />, container); | ||
var input = ReactDOM.findDOMNode(component); | ||
expect(input.value).toBe('foo'); | ||
ReactDOM.render(<LinkedInput valueLink={{value: 'boo', requestChange: function() {}}} />, container); | ||
expect(input.value).toBe('boo'); | ||
}); | ||
|
||
it('should throw', function() { | ||
var container = document.createElement('div'); | ||
var element = <LinkedInput value="foo" valueLink={{value: 'boo', requestChange: function() {}}} />; | ||
expect(function() { | ||
ReactDOM.render(element, container); | ||
}).toThrow(); | ||
}); | ||
}); |