Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80517 views
1
/**
2
* Copyright 2013-2015, 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 LinkedStateMixin
10
* @typechecks static-only
11
*/
12
13
'use strict';
14
15
var ReactLink = require("./ReactLink");
16
var ReactStateSetters = require("./ReactStateSetters");
17
18
/**
19
* A simple mixin around ReactLink.forState().
20
*/
21
var LinkedStateMixin = {
22
/**
23
* Create a ReactLink that's linked to part of this component's state. The
24
* ReactLink will have the current value of this.state[key] and will call
25
* setState() when a change is requested.
26
*
27
* @param {string} key state key to update. Note: you may want to use keyOf()
28
* if you're using Google Closure Compiler advanced mode.
29
* @return {ReactLink} ReactLink instance linking to the state.
30
*/
31
linkState: function(key) {
32
return new ReactLink(
33
this.state[key],
34
ReactStateSetters.createStateKeySetter(this, key)
35
);
36
}
37
};
38
39
module.exports = LinkedStateMixin;
40
41