Skip to content

Instantly share code, notes, and snippets.

@Chadtech
Created January 29, 2016 17:34
Show Gist options
  • Select an option

  • Save Chadtech/73a0cd650b662df6888f to your computer and use it in GitHub Desktop.

Select an option

Save Chadtech/73a0cd650b662df6888f to your computer and use it in GitHub Desktop.
# Libraries
_ = require 'lodash'
# Html is
# <body>
# <div id = "root" yeee="Dope">
# </div>
# </body>
stringifyHTML = (el) ->
attributes = _.map el.attributes,
(attr) ->
{ name, value } = attr
name + '=' + value + ' '
_.reduce attributes,
(sum, attr) -> sum + attr
(el.nodeName + ' ').toLowerCase()
stringifyVDOM = (vo) ->
keys = _.keys vo.attributes
attributes = _.map keys,
(k) ->
value = vo.attributes[k]
k + '=' + value + ' '
_.reduce attributes,
(sum, attr) -> sum + attr
vo.type + ' '
A = stringifyVDOM
type: 'div'
attributes:
id: 'root'
yeee: 'dank'
B = stringifyVDOM
type: 'div'
attributes:
id: 'root'
yeee: 'Dope'
Root = document.getElementById 'root'
Root = stringifyHTML Root
console.log 'Root is', Root
console.log 'A is', A
console.log 'B is', B
console.log 'Root is A', Root is A
console.log 'Root is B', Root is B
# Root is div id=root yeee=Dope
# A is div id=root yeee=dank
# B is div id=root yeee=Dope
# Root is A false
# Root is B true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment