-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponent.js
More file actions
46 lines (40 loc) · 1.21 KB
/
component.js
File metadata and controls
46 lines (40 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import styler from 'motion-style'
import browser from 'detect-browser'
import event from 'disposable-event'
import { CompositeDisposable } from 'sb-event-kit'
import { Component } from 'react'
const style = styler()
export default function ComponentDecorate(component) {
class ProxyComponent {
constructor(...parameters) {
this.subscriptions = new CompositeDisposable()
Component.apply(this, parameters)
component.apply(this, parameters)
}
componentWillUnmount() {
this.subscriptions.dispose()
if (component.prototype.componentWillUnmount) {
component.prototype.componentWillUnmount.call(this)
}
}
addEvent = (...args) => {
const e = event(...args)
this.subscriptions.add(e)
return e
}
}
if (browser.name !== 'safari') {
Object.defineProperty(ProxyComponent, 'name', {
get() {
return component.name
},
})
}
// set static properties
Object.keys(component).forEach(staticProp => {
ProxyComponent[staticProp] = component[staticProp]
})
Object.setPrototypeOf(component.prototype, Component.prototype)
Object.setPrototypeOf(ProxyComponent.prototype, component.prototype)
return style(ProxyComponent)
}