Skip to content

Commit 81301d4

Browse files
author
Vlad Balin
committed
added array manipulation example
1 parent 0665f1d commit 81301d4

File tree

3 files changed

+57
-11
lines changed

3 files changed

+57
-11
lines changed

app.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
/* 0 */
4545
/***/ function(module, exports, __webpack_require__) {
4646

47+
/**
48+
* ValueLink Data binding examples
49+
*
50+
* MIT License, (c) 2016 Vlad Balin, Volicon.
51+
*/
52+
4753
'use strict';
4854

4955
var _interopRequireDefault = __webpack_require__(1)['default'];
@@ -68,17 +74,27 @@
6874
displayName: 'App',
6975

7076
getInitialState: function getInitialState() {
77+
// All this stuff we can link to
7178
return {
79+
// Simple binding to inputs
7280
str: 67,
7381
bool: true,
82+
83+
// Binding to checkboxes
7484
objFlags: {
7585
a: true,
7686
b: false
7787
},
88+
89+
// Binding to checkboxes
7890
arrFlags: ['a', 'b'],
91+
92+
// binding to inputs
7993
deep: {
8094
text: ['not a number', 25]
8195
},
96+
97+
// that will be bound to radio and select list
8298
radioFlag: 'a'
8399
};
84100
},
@@ -140,6 +156,8 @@
140156

141157
var DeepLinkedInputs = function DeepLinkedInputs(_ref2) {
142158
var objLink = _ref2.objLink;
159+
160+
var arrayLink = objLink.at('text');
143161
return _react2['default'].createElement(
144162
'fieldset',
145163
null,
@@ -148,9 +166,16 @@
148166
null,
149167
'Deeply linked and validated state elements'
150168
),
151-
objLink.at('text').map(function (itemLink, i) {
169+
arrayLink.map(function (itemLink, i) {
152170
return _react2['default'].createElement(_tagsJsx.Input, { key: i, valueLink: itemLink.check(isNumber) });
153-
})
171+
}),
172+
_react2['default'].createElement(
173+
'button',
174+
{ onClick: arrayLink.action(function (arr) {
175+
return arr.push(''), arr;
176+
}) },
177+
'Add'
178+
)
154179
);
155180
};
156181

app.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/main.jsx

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* ValueLink Data binding examples
3+
*
4+
* MIT License, (c) 2016 Vlad Balin, Volicon.
5+
*/
6+
17
import './main.css'
28
import React from 'react'
39
import ReactDOM from 'react-dom'
@@ -6,17 +12,27 @@ import { Input, Select, TextArea, Radio, Checkbox } from 'tags.jsx'
612

713
const App = React.createClass( {
814
getInitialState(){
15+
// All this stuff we can link to
916
return {
17+
// Simple binding to inputs
1018
str : 67,
1119
bool : true,
20+
21+
// Binding to checkboxes
1222
objFlags : {
1323
a : true,
1424
b : false
1525
},
26+
27+
// Binding to checkboxes
1628
arrFlags : [ 'a', 'b' ],
29+
30+
// binding to inputs
1731
deep : {
1832
text : [ 'not a number', 25 ]
1933
},
34+
35+
// that will be bound to radio and select list
2036
radioFlag : 'a'
2137
}
2238
},
@@ -67,14 +83,19 @@ const SimpleBinding = ({ strLink, boolLink }) => {
6783
);
6884
}
6985

70-
const DeepLinkedInputs = ({ objLink }) => (
71-
<fieldset>
72-
<legend>Deeply linked and validated state elements</legend>
73-
{ objLink.at( 'text' ).map( ( itemLink, i ) =>(
74-
<Input key={ i } valueLink={ itemLink.check( isNumber ) } />
75-
))}
76-
</fieldset>
77-
);
86+
const DeepLinkedInputs = ({ objLink }) => {
87+
const arrayLink = objLink.at( 'text' );
88+
return (
89+
<fieldset>
90+
<legend>Deeply linked and validated state elements</legend>
91+
{ arrayLink.map( ( itemLink, i ) =>(
92+
<Input key={ i } valueLink={ itemLink.check( isNumber ) } />
93+
))}
94+
95+
<button onClick={ arrayLink.action( arr => ( arr.push( '' ), arr ) )}>Add</button>
96+
</fieldset>
97+
);
98+
}
7899

79100
const CheckboxObjGroup = ({ flagsLink }) => (
80101
<fieldset>

0 commit comments

Comments
 (0)