UNPKG

chromogen-zustand

Version:

simple, interaction-driven Jest test generator for Recoil and React Hooks apps

100 lines (99 loc) 3.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateHooksFile = exports.generateStateTreeObj = exports.createPrevStateObj = exports.hookStyles = void 0; const hooks_ledger_1 = require("../utils/hooks-ledger"); const hooks_output_1 = require("../output/hooks-output"); const hooksButtonStyle = { display: 'inline-block', margin: '8px', marginLeft: '13px', padding: '0px', height: '25px', width: '65px', borderRadius: '4px', justifyContent: 'space-evenly', border: '1px', cursor: 'pointer', color: '#90d1f0', fontSize: '10px', }; const hooksDivStyle = { display: 'flex', position: 'absolute', bottom: '100px', left: '100px', backgroundColor: '#aaa', borderRadius: '4px', margin: 0, padding: 0, zIndex: 999999, }; const hooksPlayStyle = { boxSizing: 'border-box', marginLeft: '25px', borderStyle: 'solid', borderWidth: '7px 0px 7px 14px', }; const hooksPauseStyle = { width: '14px', height: '14px', borderWidth: '0px 0px 0px 10px', borderStyle: 'double', marginLeft: '27px', }; exports.hookStyles = { hooksButtonStyle, hooksDivStyle, hooksPlayStyle, hooksPauseStyle }; const createPrevStateObj = (stateArrays) => { const stateObj = {}; for (let i = 0; i < stateArrays.length; i++) { if (stateArrays[i][1] !== undefined) { const key = stateArrays[i][0]; if (key in stateObj) { const oldValue = stateObj[key]; if (Array.isArray(stateArrays[i][1])) { oldValue.push(stateArrays[i][1][0]); } else { oldValue.push(stateArrays[i][1]); } stateObj[key] = oldValue; console.log('state[key]', stateObj[key]); } else { if (!Array.isArray(stateArrays[i][1])) { stateObj[key] = [stateArrays[i][1]]; } else { stateObj[key] = stateArrays[i][1]; } } } } console.log('state object inside create previous state object', stateObj); return stateObj; }; exports.createPrevStateObj = createPrevStateObj; const generateStateTreeObj = (stateObj) => { const d3Obj = { name: 'root', children: [] }; for (const property in stateObj) { const innerObj = { name: property, children: [] }; for (let i = 0; i < stateObj[property].length; i++) { innerObj.children.push({ name: `${stateObj[property][i]}` }); } d3Obj.children.push(innerObj); } console.log('d3 object inside generate state tree object', d3Obj); return d3Obj; }; exports.generateStateTreeObj = generateStateTreeObj; const generateHooksFile = (setHooksFile) => { const blob = new Blob([(0, hooks_output_1.hooksOutput)(hooks_ledger_1.hooksLedger)]); setHooksFile(URL.createObjectURL(blob)); return [(0, hooks_output_1.hooksOutput)(hooks_ledger_1.hooksLedger)]; }; exports.generateHooksFile = generateHooksFile;