Skip to content
This repository has been archived by the owner on Nov 23, 2017. It is now read-only.

Some common DOM manipulations require mutable fields #202

Open
mfrawley opened this issue Nov 4, 2013 · 1 comment
Open

Some common DOM manipulations require mutable fields #202

mfrawley opened this issue Nov 4, 2013 · 1 comment

Comments

@mfrawley
Copy link

mfrawley commented Nov 4, 2013

e.g. this won't work
let show (el:DomElement) = el.style.display = 'block'

@joneshf
Copy link
Collaborator

joneshf commented Nov 5, 2013

Yeah, it's a bit tough to use mutability. You have a few options. Here's two.

Use something like underscore to update it.

let _ = require 'underscore'
let show el = _.extend el.style {display: 'block'}

Use something like fantasy-lenses to still deal with immutability.

let ol = (require 'fantasy-lenses').objectLens
let show2 el =
  (((ol 'style') .andThen(ol 'display')).run el).set 'block'

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants