Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Integration PureScript and Halogen into JavaScr...

Integration PureScript and Halogen into JavaScript Applications

Avatar for Hardy Jones

Hardy Jones

May 25, 2017

More Decks by Hardy Jones

Other Decks in Programming

Transcript

  1. Who am I? • Programming for 5 years • Former

    SlamData Employee • Current NoRedInk Employee
  2. Who am I? • Programming for 5 years • Former

    SlamData Employee • Current NoRedInk Employee • @st58 on twitter, joneshf everywhere else
  3. JavaScript Refresher • ES2015 syntax ◦ Arrow functions ◦ Destructuring

    objects ◦ Import/Export statements • Callbacks
  4. Tasks 1. Change the heading to something else. E.g. “The

    Best Shopping Cart!!” 2. Make an alert appear when you click “Checkout”
  5. Redux • Library that helps you manage state • Independent

    of React, but often used together • Let’s play with Redux!
  6. Tasks 1. Add a button that resets the products 2.

    Add a button that buys the rest of a product’s inventory
  7. PureScript • Strongly typed • Statically typed • Compiles to

    JavaScript ◦ Many other languages as well
  8. PureScript • Strongly typed • Statically typed • Compiles to

    JavaScript ◦ Many other languages as well • Purity enforced
  9. PureScript • Strongly typed • Statically typed • Compiles to

    JavaScript ◦ Many other languages as well • Purity enforced • Immutable values
  10. PureScript • Strongly typed • Statically typed • Compiles to

    JavaScript ◦ Many other languages as well • Purity enforced • Immutable values • Let’s play with PureScript!
  11. PureScript • npm install -D purescript pulp bower • Add

    a script: “bower”: “bower” • Add a script: “pulp psci”: “pulp psci”
  12. PureScript • npm install -D purescript pulp bower • Add

    a script: “bower”: “bower” • Add a script: “pulp psci”: “pulp psci” • npm run bower -- install -S purescript-prelude purescript-console
  13. PureScript • npm install -D purescript pulp bower • Add

    a script: “bower”: “bower” • Add a script: “pulp psci”: “pulp psci” • npm run bower -- install -S purescript-prelude purescript-console • npm run bower -- install -D purescript-psci-support
  14. Compiling to JS • Add a script “pulp-build”: “pulp --watch

    build --build-path src/purs” • npm run pulp-build
  15. Compiling to JS • Add a script “pulp-build”: “pulp --watch

    build --build-path src/purs” • npm run pulp-build • Let’s format the string in PureScript and use it in JavaScript!
  16. Tasks 1. Create a module “Product.purs” in src 2. Implement

    “format” 3. Use “format” from “Product.js”
  17. Tasks 1. Create a module “Product.purs” in src 2. Implement

    “format” 3. Use “format” from “Product.js” 4. Make a JS friendly “format” a. npm run bower -- install -S purescript-functions
  18. Eff

  19. Eff • A data type that lets you communicate which

    “effects” a procedure needs
  20. Eff • A data type that lets you communicate which

    “effects” a procedure needs • Not executable from within PureScript*
  21. Eff • A data type that lets you communicate which

    “effects” a procedure needs • Not executable from within PureScript* • Under the hood, it’s a nullary function that runs a procedure
  22. Eff • A data type that lets you communicate which

    “effects” a procedure needs • Not executable from within PureScript* • Under the hood, it’s a nullary function that runs a procedure • Let’s use Eff from JavaScript!
  23. Halogen • Library that helps you build UIs better •

    Self-contained components • State is manged by a “query algebra”
  24. Halogen • Library that helps you build UIs better •

    Self-contained components • State is manged by a “query algebra” ◦ Actions change state
  25. Halogen • Library that helps you build UIs better •

    Self-contained components • State is manged by a “query algebra” ◦ Actions change state ◦ Requests provide information (may also change state)
  26. Halogen • Library that helps you build UIs better •

    Self-contained components • State is manged by a “query algebra” ◦ Actions change state ◦ Requests provide information (may also change state) • Let’s play with Halogen!
  27. Tasks 1. Implement “product” in Halogen a. npm run bower

    -- install -S purescript-halogen 2. Implement a Halogen runner in JavaScript
  28. Review 1. React 2. Redux 3. PureScript 4. Using PureScript

    from JavaScript 5. Eff 6. Types 7. Halogen
  29. Review 1. React 2. Redux 3. PureScript 4. Using PureScript

    from JavaScript 5. Eff 6. Types 7. Halogen 8. Using Halogen from JavaScript