1
1
import * as types from '../constants/ActionTypes' ;
2
+ import { OPTIONS_PRESET_DEFAULT } from "../containers/OptionsContainer" ;
2
3
3
4
const obfuscationWorker = new Worker ( '../workers/obfuscation-worker.js?v=' + new Date ( ) . getTime ( ) ) ;
4
5
6
+ export const OBFUSCATOR_WORKER_OBFUSCATE_EVENT = 'OBFUSCATOR_WORKER_OBFUSCATE_EVENT' ;
7
+ export const OBFUSCATOR_WORKER_GET_OPTIONS_BY_PRESET_EVENT = 'OBFUSCATOR_WORKER_GET_OPTIONS_BY_PRESET_EVENT' ;
8
+
5
9
export const updateCode = ( code ) => ( {
6
10
'type' : types . UPDATE_CODE ,
7
11
code
@@ -25,8 +29,11 @@ export const obfuscateCode = (code, options) => {
25
29
}
26
30
27
31
const message = {
28
- code,
29
- options
32
+ type : OBFUSCATOR_WORKER_OBFUSCATE_EVENT ,
33
+ payload : {
34
+ code,
35
+ options
36
+ }
30
37
} ;
31
38
32
39
obfuscationWorker . postMessage ( message ) ;
@@ -39,36 +46,39 @@ export const obfuscateCode = (code, options) => {
39
46
40
47
resolve ( result ) ;
41
48
} ;
42
- } ) ,
49
+ } )
43
50
} ) ;
51
+ } ;
52
+ } ;
44
53
45
- /**
46
- const request = new Request('/obfuscate', {
47
- method: 'POST',
48
- credentials: 'same-origin',
49
- headers: {
50
- 'Accept': 'application/json',
51
- 'Content-Type': 'application/json'
52
- },
53
- body: JSON.stringify(body),
54
+ export const resetOptions = ( ) => {
55
+ return ( dispatch ) => {
56
+ dispatch ( {
57
+ 'type' : types . RESET_OPTIONS ,
54
58
} ) ;
55
-
56
- return {
57
- type: types.OBFUSCATE,
58
- payload: fetch(request).then((response) => response.json()),
59
- }
60
- */
59
+ setOptionsPreset ( OPTIONS_PRESET_DEFAULT ) ;
61
60
} ;
62
61
} ;
63
62
64
- export const resetOptions = ( ) => ( {
65
- 'type' : types . RESET_OPTIONS ,
66
- } ) ;
63
+ export const setOptionsPreset = ( optionsPreset ) => {
64
+ return ( dispatch ) => {
65
+ const message = {
66
+ type : OBFUSCATOR_WORKER_GET_OPTIONS_BY_PRESET_EVENT ,
67
+ payload : { optionsPreset }
68
+ } ;
67
69
68
- export const setOptionsPreset = ( optionsPreset ) => ( {
69
- 'type' : types . SET_OPTIONS_PRESET ,
70
- optionsPreset
71
- } ) ;
70
+ obfuscationWorker . postMessage ( message ) ;
71
+ obfuscationWorker . onmessage = function ( event ) {
72
+ const options = JSON . parse ( event . data ) ;
73
+
74
+ dispatch ( {
75
+ type : types . SET_OPTIONS_PRESET ,
76
+ optionsPreset,
77
+ options
78
+ } ) ;
79
+ } ;
80
+ } ;
81
+ } ;
72
82
73
83
export const toggleOption = ( optionType ) => ( {
74
84
'type' : optionType
0 commit comments