2

After searching for some time I found in Pursuit the module DOM.HTML.History which has the data type DocumentTitle. This type could probably be used together with the function

replaceState ::
  ∀ e. Foreign -> DocumentTitle -> URL -> History -> Eff (history :: HISTORY | e) Unit

To change the document.title property of the page, however, I can't find examples showing how to call this function (e.g., where do I get the external Foreign data type?). Also, I'm not even sure if this function would do what I expect it to do...

kazuoua
  • 313
  • 4
  • 9

2 Answers2

1

In the unfortunate case that the Purescript team didn't include in their core API a way to change the document title, it's still possible to do so by making use of purescript's handy FFI mechanism.

Add these two files into your project:

Document.js

exports.setDocumentTitle =
  function (title)
  {
    return function ()
    {
      window.document.title = title;
    };
  };

Document.purs

module Document
where

import Control.Monad.Eff (kind Effect, Eff)
import Data.Unit (Unit)

foreign import data DOCUMENT :: Effect

foreign import setDocumentTitle ::
  ∀ fx . String -> Eff (document :: DOCUMENT | fx) Unit

Now you can call setDocumentTitle as you would call Console's log function, except the effect would be DOCUMENT instead of CONSOLE, of course.

kazuoua
  • 313
  • 4
  • 9
0

kazouas answer would look like this (in PS 0.12)

import Effect (Effect)
import Data.Unit (Unit)

foreign import setDocumentTitle :: String -> Effect Unit

Javascript remains the same.

Alebon
  • 1,189
  • 2
  • 11
  • 24