Passed
Push — master ( 8f169b...36019d )
by Rafael
01:27
created

src/app/save/control.js   A

Size

Lines of Code 33

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
nc 1
dl 0
loc 33
rs 10
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A control.js ➔ ??? 0 3 1
1
import './style.scss';
2
import templateHTML from './template.html';
3
import { Storage } from '../storage';
4
5
export class Control {
6
	constructor() {
7
		this.storage = new Storage();
8
	}
9
10
	getItem( settingName ) {
11
		return this.storage.getItem( settingName );
12
	}
13
14
	render() {
15
		this.$control = $( templateHTML );
16
		this.$save = this.$control.find( '.save-settings' );
17
		this.$clear = this.$control.find( '.clear-storage' );
18
19
		$( 'save-ui' ).replaceWith( this.$control );
20
	}
21
22
	setup( settingName, getValueCb ) {
23
		this.$save.on( 'click', () => {
24
			this.storage.setItem( settingName, getValueCb( settingName ) );
25
			setTimeout( () => location.reload() );
26
		} );
27
28
		this.$clear.on( 'click', () => {
29
			this.storage.removeItem( settingName );
30
			setTimeout( () => location.reload() );
31
		} );
32
	}
33
}
34