11import * as types from '../constants/ActionTypes' ;
2+ import { OPTIONS_PRESET_DEFAULT } from "../containers/OptionsContainer" ;
23
34const obfuscationWorker = new Worker ( '../workers/obfuscation-worker.js?v=' + new Date ( ) . getTime ( ) ) ;
45
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+
59export const updateCode = ( code ) => ( {
610 'type' : types . UPDATE_CODE ,
711 code
@@ -25,8 +29,11 @@ export const obfuscateCode = (code, options) => {
2529 }
2630
2731 const message = {
28- code,
29- options
32+ type : OBFUSCATOR_WORKER_OBFUSCATE_EVENT ,
33+ payload : {
34+ code,
35+ options
36+ }
3037 } ;
3138
3239 obfuscationWorker . postMessage ( message ) ;
@@ -39,36 +46,39 @@ export const obfuscateCode = (code, options) => {
3946
4047 resolve ( result ) ;
4148 } ;
42- } ) ,
49+ } )
4350 } ) ;
51+ } ;
52+ } ;
4453
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 ,
5458 } ) ;
55-
56- return {
57- type: types.OBFUSCATE,
58- payload: fetch(request).then((response) => response.json()),
59- }
60- */
59+ setOptionsPreset ( OPTIONS_PRESET_DEFAULT ) ;
6160 } ;
6261} ;
6362
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+ } ;
6769
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+ } ;
7282
7383export const toggleOption = ( optionType ) => ( {
7484 'type' : optionType
0 commit comments