Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ function createClass(toNullable, spec) {
}
exports["createClass'"] = createClass;

function capitalize(s) {
if (!s)
return s;
return s.charAt(0).toUpperCase() + s.slice(1);
};

function createClassStateless(dict) {
return function (f) {
if (!f.displayName)
f.displayName = capitalize(f.name);
return f;
};
};
exports.createClassStateless = createClassStateless;

function forceUpdateCbImpl(this_, cb) {
this_.forceUpdate(function() {
return cb();
Expand Down
12 changes: 9 additions & 3 deletions src/React.purs
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,17 @@ createClass :: forall props state render eff.
ReactSpec props state render eff -> ReactClass props
createClass spc = runFn2 createClass' toNullable spc

-- | Create a stateless React class.
createClassStateless :: forall props render.
-- | Create a stateless React class. When using a non anonymous function the
-- | displayName will be the capitalized name of the function, e.g.
-- | ``` purescript
-- | helloWorld = createClassStatelesss hellowWorldCls
-- | where
-- | hellowWorldCls props = ...
-- | ```
-- | Then the `displayName` will be set up to `HellowWorldCls`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue #118 @ethul this might be a bit surprising but it's best of what we can get.

foreign import createClassStateless :: forall props render.
ReactRender render =>
(props -> render) -> ReactClass props
createClassStateless = unsafeCoerce

-- | Create a stateless React class with children access.
createClassStateless' :: forall props render.
Expand Down