Comments (3)
For interop we need to be able to pass "props" when we render a class. Are you interested in using Haskell-defined react classes from JS? It looks like React has support for its own dynamic type checking http://facebook.github.io/react/docs/reusable-components.html which we could utilize! Unfortunately I feel as though we'll need yet another type variable props for each class.
from react-haskell.
Hey John, can you elaborate on what you're thinking with some examples? I understand what you're getting at, but would like a concrete example so we can hash out the details.
from react-haskell.
Hi Joel, was going to contribute more to this repo this week, but unfortunately the rest of my life got slightly in the way. I think I am close to getting composable classes (React 12.2), but it will certainly break animations, which I would need to fix before I could expect you to accept a PR. I also need to read up on the React 13.0b chances and flux, so I can think more about #8 .
So, when you instantiate a react JS class using createElement
, you pass it a props hash. In react HS, we had better be able to
- Pass props when instantiating imported classes using
render
or (not yet written)reactClass_
- We have to define the types of the props in order to this, but the dynamic type checking doesn't really help here, since the type of the values we pass have been checked at compile time
- Accept props when our classes are instantiated from javascript code
- Here, we have no guarantee that the props are the correct type. It might be a good idea to make a
createClass'
that is likecreateClass
but generates a class with the correctpropTypes
. That way, JS users would get sensible and familiar type error messages when they instantiate the class, rather than having to pick through our unreadable compiled code. I really hope it can be done without TemplateHaskell.
- Here, we have no guarantee that the props are the correct type. It might be a good idea to make a
Maybe that's for another issue on here, but for basic interop, how about something like:
importing someone's javascript class:
import Haste.Foreign
import React.Foreign -- TODO
-- import the class
data LaunchControlProps = LaunchControlProps { countDown :: Int, capsule :: String }
instance ToProps LaunchControlProps where
toProps = ffi "function(cd,c){return {countDown: cd, capsule: c}}" -- Still unsure how to make a JS hash without using the ffi or JSON. I must look really stupid.
launchControl :: ReactClass () () () LaunchControlProps
launchControl = importClass "launchControlReactClassImplementedInJavaScript"
-- markup
reactClass_ launchControl $ LaunchControlProps 10 "Soyuz"
exporting a Haskell React class
import Haste.Foreign
import React.Foreign
-- Create a class using Haskell
data RocketProps = RocketProps { throttle :: Double, thrust :: Double }
-- this could rather cunningly define propTypes
instance FromProps RocketProps where
fromProps props = RocketProps t f
where (t,f) = ffi "function(props) {return [props.throttle, props.thrust]}"
rocketPanel :: ReactClass Foo Bar Quux RocketProps
rocketPanel = ...
-- export the class
main :: IO ()
exportClass "RocketPanel" rocketPanel
What do you reckon?
from react-haskell.
Related Issues (19)
- figure out packaging HOT 1
- routing
- enhanced animation
- fps meter HOT 1
- Cannot install from hackage HOT 2
- todomvc example is broken HOT 1
- Only one element rendering at each level in the DOM HOT 1
- Signals delayed until first animation frame [question] HOT 2
- finish event type definitions HOT 1
- Functor instance for ReactNode HOT 1
- Failed to compile HOT 2
- how to run this example
- Failed to install
- Fix hackage build HOT 5
- dangerouslySetInnerHTML
- lifecycle methods
- How to run the examples? HOT 2
- first class classes HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-haskell.