improve loading opcodes

pull/1344/head
yann300 3 years ago committed by joseph izang
parent 300d516b0e
commit 80b9f8c77a
  1. 18
      libs/remix-ui/debugger-ui/src/reducers/assembly-items.ts

@ -20,6 +20,14 @@ export const initialState = {
hasError: null hasError: null
} }
const reducedOpcode = (opCodes) => {
const length = 50
let bottom = opCodes.index - 10
bottom = bottom < 0 ? 0 : bottom
const top = bottom + length
return { top, bottom, display: opCodes.code.slice(bottom, top) }
}
export const reducer = (state = initialState, action: Action) => { export const reducer = (state = initialState, action: Action) => {
switch (action.type) { switch (action.type) {
case 'FETCH_OPCODES_REQUEST': { case 'FETCH_OPCODES_REQUEST': {
@ -34,16 +42,12 @@ export const reducer = (state = initialState, action: Action) => {
const opCodes = action.payload.address === state.opCodes.address ? { const opCodes = action.payload.address === state.opCodes.address ? {
...state.opCodes, index: action.payload.index ...state.opCodes, index: action.payload.index
} : deepEqual(action.payload.code, state.opCodes.code) ? state.opCodes : action.payload } : deepEqual(action.payload.code, state.opCodes.code) ? state.opCodes : action.payload
const top = opCodes.index - 3 > 0 ? opCodes.index - 3 : 0
const bottom = opCodes.index + 4 < opCodes.code.length ? opCodes.index + 4 : opCodes.code.length
const display = opCodes.code.slice(top, bottom)
const reduced = reducedOpcode(opCodes)
return { return {
opCodes, opCodes,
display, display: reduced.display,
index: display.findIndex(code => code === opCodes.code[opCodes.index]), index: reduced.display.findIndex(code => code === opCodes.code[opCodes.index]),
top,
bottom,
isRequesting: false, isRequesting: false,
isSuccessful: true, isSuccessful: true,
hasError: null hasError: null

Loading…
Cancel
Save