Skip to content

Commit 8aa091e

Browse files
author
Michael Trotter
committed
Reorganize for docs
1 parent a03d67d commit 8aa091e

4 files changed

Lines changed: 387 additions & 212 deletions

File tree

examples/counter/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"dependencies": {
3-
"react": "^16.4.2",
4-
"react-dom": "^16.4.2"
3+
"react": "16.6.0",
4+
"react-dom": "16.6.0"
55
},
66
"devDependencies": {
7-
"browserify": "^16.2.2"
7+
"browserify": "16.2.3"
88
}
99
}

examples/counter/src/Counter.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import Prelude
55
import React.Basic (Component, JSX, StateUpdate(..), capture_, createComponent, make)
66
import React.Basic.DOM as R
77

8+
component :: Component
9+
component = createComponent "Counter"
10+
811
type Props =
912
{ label :: String
1013
}
@@ -14,7 +17,7 @@ data Action
1417

1518
counter :: Props -> JSX
1619
counter = make component
17-
{ initialState = { counter: 0 }
20+
{ initialState = { counter: 0, dummy: 0 }
1821

1922
, update = \self -> case _ of
2023
Increment ->
@@ -26,6 +29,3 @@ counter = make component
2629
, children: [ R.text (self.props.label <> ": " <> show self.state.counter) ]
2730
}
2831
}
29-
30-
component :: Component
31-
component = createComponent "Counter"

src/React/Basic.js

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,6 @@
33
var React = require("react");
44
var Fragment = React.Fragment || "div";
55

6-
exports.readProps = function(self) {
7-
return self.instance_.props.$$props;
8-
};
9-
10-
exports.readState = function(self) {
11-
var state = self.instance_.state;
12-
return state === null ? null : state.$$state;
13-
};
14-
15-
exports.send_ = function(buildStateUpdate) {
16-
return function(self, action) {
17-
if (!self.instance_.$$mounted) {
18-
exports.warningUnmountedComponentAction(self, action);
19-
return;
20-
}
21-
var sideEffects = null;
22-
self.instance_.setState(
23-
function(s) {
24-
var setStateContext = self.instance_.toSelf();
25-
setStateContext.state = s.$$state;
26-
var updates = buildStateUpdate(
27-
self.instance_.$$spec.update(setStateContext)(action)
28-
);
29-
if (updates.effects !== null) {
30-
sideEffects = updates.effects;
31-
}
32-
if (updates.state !== null && updates.state !== s.$$state) {
33-
return { $$state: updates.state };
34-
} else {
35-
return null;
36-
}
37-
},
38-
function() {
39-
if (sideEffects !== null) {
40-
sideEffects(this.toSelf())();
41-
}
42-
}
43-
);
44-
};
45-
};
46-
476
exports.createComponent_ = function(defaultUpdate) {
487
var defaultInitialState = null;
498
var defaultShouldUpdate = function() {
@@ -150,6 +109,47 @@ exports.createComponent_ = function(defaultUpdate) {
150109
};
151110
};
152111

112+
exports.send_ = function(buildStateUpdate) {
113+
return function(self, action) {
114+
if (!self.instance_.$$mounted) {
115+
exports.warningUnmountedComponentAction(self, action);
116+
return;
117+
}
118+
var sideEffects = null;
119+
self.instance_.setState(
120+
function(s) {
121+
var setStateContext = self.instance_.toSelf();
122+
setStateContext.state = s.$$state;
123+
var updates = buildStateUpdate(
124+
self.instance_.$$spec.update(setStateContext)(action)
125+
);
126+
if (updates.effects !== null) {
127+
sideEffects = updates.effects;
128+
}
129+
if (updates.state !== null && updates.state !== s.$$state) {
130+
return { $$state: updates.state };
131+
} else {
132+
return null;
133+
}
134+
},
135+
function() {
136+
if (sideEffects !== null) {
137+
sideEffects(this.toSelf())();
138+
}
139+
}
140+
);
141+
};
142+
};
143+
144+
exports.readProps = function(self) {
145+
return self.instance_.props.$$props;
146+
};
147+
148+
exports.readState = function(self) {
149+
var state = self.instance_.state;
150+
return state === null ? null : state.$$state;
151+
};
152+
153153
exports.make = function($$spec) {
154154
return function($$props) {
155155
var props = {
@@ -160,6 +160,8 @@ exports.make = function($$spec) {
160160
};
161161
};
162162

163+
exports.empty = null;
164+
163165
exports.keyed_ = function(key, child) {
164166
return React.createElement(Fragment, { key: key }, child);
165167
};
@@ -177,13 +179,6 @@ exports.fragment = function(children) {
177179
return React.createElement.apply(null, [Fragment, {}].concat(children));
178180
};
179181

180-
exports.fragmentKeyed_ = function(key, children) {
181-
return React.createElement.apply(
182-
null,
183-
[Fragment, { key: key }].concat(children)
184-
);
185-
};
186-
187182
exports.displayNameFromComponentSpec = function($$spec) {
188183
return $$spec.$$type.displayName || "[unknown]";
189184
};

0 commit comments

Comments
 (0)