Skip to content

Instantly share code, notes, and snippets.

@jongacnik
Created October 12, 2018 17:38
Show Gist options
  • Save jongacnik/99f1014bdcfd3e0445d17fc65e6ad787 to your computer and use it in GitHub Desktop.
Save jongacnik/99f1014bdcfd3e0445d17fc65e6ad787 to your computer and use it in GitHub Desktop.
/**
* self managing nanocomponent instance proof of concept,
* unfortunately we get hit with proxy node bugz...
*
* idea here is you reset SOFT_IMAGE_COUNT on choo RENDER
*/
var html = require('choo/html')
var Component = require('choo/component')
window.SOFT_IMAGE_COUNT = 0
window.SOFT_IMAGE_INDEX = []
module.exports = function (file) {
if (!window.SOFT_IMAGE_INDEX[window.SOFT_IMAGE_COUNT]) {
console.log('create soft image', window.SOFT_IMAGE_COUNT)
window.SOFT_IMAGE_INDEX[window.SOFT_IMAGE_COUNT] = new SoftImage(window.SOFT_IMAGE_COUNT)
} else {
console.log('fetch soft image', window.SOFT_IMAGE_COUNT)
}
var element = window.SOFT_IMAGE_INDEX[window.SOFT_IMAGE_COUNT].render(file, window.SOFT_IMAGE_COUNT)
window.SOFT_IMAGE_COUNT++
console.log('increment soft image', window.SOFT_IMAGE_COUNT)
return element
}
class SoftImage extends Component {
constructor(id) {
super(id)
this.count = id
}
createElement (file, count) {
this.url = file.url
return html`<img src=${file.url}>`
}
update (file, count) {
console.log(this.count, count)
if (file.url !== this.url) {
console.log(file.url, this.url)
return true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment