-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
35 lines (29 loc) · 969 Bytes
/
main.js
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
import App from './app/App'
import React from 'react'
import { render, unmountComponentAtNode } from 'react-dom'
import Cache from './helpers/cache'
export default class Library {
constructor (elementRef, onSuccess, options) {
// set options to be used by others
Cache.set('options', options)
this.onSuccess = onSuccess
// get the elements to trigger our payment form
this.elements = [...document.querySelectorAll(elementRef)]
.map(element => {
element.addEventListener('click', this.mountApp.bind(this))
return element
})
this.initFormContainer()
}
// kill everything about the app and events
unmountApp () {
unmountComponentAtNode(this.container)
}
mountApp () {
render(<App onSuccess={this.onSuccess} close={this.unmountApp.bind(this)} />, this.container)
}
initFormContainer () {
this.container = document.createElement('div')
document.body.appendChild(this.container)
}
}