1 | /**
|
2 | * Copyright (c) 2013-present, Facebook, Inc.
|
3 | *
|
4 | * This source code is licensed under the MIT license found in the
|
5 | * LICENSE file in the root directory of this source tree.
|
6 | *
|
7 | */
|
8 |
|
9 | ;
|
10 |
|
11 | var ReactLink = require('./ReactLink');
|
12 | var ReactStateSetters = require('./ReactStateSetters');
|
13 |
|
14 | /**
|
15 | * A simple mixin around ReactLink.forState().
|
16 | * See https://facebook.github.io/react/docs/two-way-binding-helpers.html
|
17 | */
|
18 | var LinkedStateMixin = {
|
19 | /**
|
20 | * Create a ReactLink that's linked to part of this component's state. The
|
21 | * ReactLink will have the current value of this.state[key] and will call
|
22 | * setState() when a change is requested.
|
23 | *
|
24 | * @param {string} key state key to update.
|
25 | * @return {ReactLink} ReactLink instance linking to the state.
|
26 | */
|
27 | linkState: function (key) {
|
28 | return new ReactLink(this.state[key], ReactStateSetters.createStateKeySetter(this, key));
|
29 | }
|
30 | };
|
31 |
|
32 | module.exports = LinkedStateMixin; |
\ | No newline at end of file |