Skip to content

Commit a51415a

Browse files
author
Michael Trotter
committed
Fix statelessComponent
1 parent 7f80ace commit a51415a

2 files changed

Lines changed: 3 additions & 72 deletions

File tree

src/React/Basic.js

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -121,76 +121,6 @@ exports.createComponent_ = function(noUpdate, buildStateUpdate, displayName) {
121121
};
122122
};
123123

124-
exports.createStatelessComponent = function(displayName) {
125-
function contextToSelf(instance) {
126-
var self = {
127-
props: instance.props.$$props,
128-
state: null,
129-
readProps: function() {
130-
return self.instance_.props.$$props;
131-
},
132-
readState: function() {
133-
return null;
134-
},
135-
send: function() {
136-
return function() {};
137-
},
138-
instance_: instance
139-
};
140-
return self;
141-
}
142-
143-
var defaultInitialState = null;
144-
var defaultShouldUpdate = function() {
145-
return function() {
146-
return function() {
147-
return true;
148-
};
149-
};
150-
};
151-
var defaultDidMount = function() {
152-
return function() {};
153-
};
154-
var defaultDidUpdate = function() {
155-
return function() {};
156-
};
157-
var defaultWillUnmount = function() {
158-
return function() {};
159-
};
160-
var defaultUpdate = function() {
161-
return function() {
162-
return noUpdate;
163-
};
164-
};
165-
var defaultRender = function() {
166-
return false;
167-
};
168-
169-
var Component = function constructor(props) {
170-
this.$$spec = props.$$spec;
171-
return this;
172-
};
173-
174-
Component.prototype = Object.create(React.Component.prototype);
175-
176-
Component.displayName = displayName;
177-
178-
Component.prototype.render = function() {
179-
return this.$$spec.render(contextToSelf(this));
180-
};
181-
182-
return {
183-
$$type: Component,
184-
initialState: defaultInitialState,
185-
shouldUpdate: defaultShouldUpdate,
186-
didMount: defaultDidMount,
187-
didUpdate: defaultDidUpdate,
188-
willUnmount: defaultWillUnmount,
189-
update: defaultUpdate,
190-
render: defaultRender
191-
};
192-
};
193-
194124
exports.make = function($$spec) {
195125
return function($$props) {
196126
var props = {

src/React/Basic.purs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ foreign import createComponent_
220220
})
221221

222222
-- | Creates a named, stateless component
223-
foreign import createStatelessComponent
223+
createStatelessComponent
224224
:: String
225-
-> { "$$type" :: forall props state action. ComponentType props state action
225+
-> { "$$type" :: forall props state action. ComponentType props Void Void
226226
, initialState :: Void
227227
, shouldUpdate :: forall props. LimitedSelf props Void -> props -> Void -> Boolean
228228
, didMount :: forall props. Self props Void Void -> Effect Unit
@@ -231,6 +231,7 @@ foreign import createStatelessComponent
231231
, update :: forall props. Update props Void Void
232232
, render :: forall props. Self props Void Void -> JSX
233233
}
234+
createStatelessComponent = createComponent
234235

235236
-- | An empty node. This is often useful when you would like to conditionally
236237
-- | show something, but you don't want to (or can't) modify the `children` prop

0 commit comments

Comments
 (0)