removing dead code

This commit is contained in:
Martin McKeaveney 2020-10-29 11:46:26 +00:00
parent 76fa6c6f23
commit 2f0a19a152
5 changed files with 0 additions and 107 deletions

View File

@ -1,33 +0,0 @@
const buildCodeForSingleScreen = screen => {
let code = ""
const walkProps = props => {
if (props._code && props._code.trim().length > 0) {
code += buildComponentCode(props)
}
if (!props._children) return
for (let child of props._children) {
walkProps(child)
}
}
walkProps(screen.props)
return code
}
export const buildCodeForScreens = screens => {
let allfunctions = ""
for (let screen of screens) {
allfunctions += buildCodeForSingleScreen(screen)
}
return `({ ${allfunctions} });`
}
const buildComponentCode = componentProps =>
`"${componentProps._id}" : (render, context, state, route) => {
${componentProps._code}
},
`

View File

@ -1,17 +0,0 @@
export const insertCodeMetadata = props => {
if (props._code && props._code.length > 0) {
props._codeMeta = codeMetaData(props._code)
}
if (!props._children || props._children.length === 0) return
for (let child of props._children) {
insertCodeMetadata(child)
}
}
const codeMetaData = code => {
return {
dependsOnStore: RegExp(/(state.)/g).test(code),
}
}

View File

@ -11,9 +11,7 @@ import {
getBuiltin, getBuiltin,
} from "components/userInterface/pagesParsing/createProps" } from "components/userInterface/pagesParsing/createProps"
import { fetchComponentLibDefinitions } from "../loadComponentLibraries" import { fetchComponentLibDefinitions } from "../loadComponentLibraries"
import { buildCodeForScreens } from "../buildCodeForScreens"
import { generate_screen_css } from "../generate_css" import { generate_screen_css } from "../generate_css"
import { insertCodeMetadata } from "../insertCodeMetadata"
import analytics from "analytics" import analytics from "analytics"
import { uuid } from "../uuid" import { uuid } from "../uuid"
import { import {
@ -60,15 +58,12 @@ export const getStore = () => {
store.setCurrentPage = setCurrentPage(store) store.setCurrentPage = setCurrentPage(store)
store.createLink = createLink(store) store.createLink = createLink(store)
store.createScreen = createScreen(store) store.createScreen = createScreen(store)
store.addStylesheet = addStylesheet(store)
store.removeStylesheet = removeStylesheet(store)
store.savePage = savePage(store) store.savePage = savePage(store)
store.addChildComponent = addChildComponent(store) store.addChildComponent = addChildComponent(store)
store.selectComponent = selectComponent(store) store.selectComponent = selectComponent(store)
store.setComponentProp = setComponentProp(store) store.setComponentProp = setComponentProp(store)
store.setPageOrScreenProp = setPageOrScreenProp(store) store.setPageOrScreenProp = setPageOrScreenProp(store)
store.setComponentStyle = setComponentStyle(store) store.setComponentStyle = setComponentStyle(store)
store.setComponentCode = setComponentCode(store)
store.setScreenType = setScreenType(store) store.setScreenType = setScreenType(store)
store.getPathToComponent = getPathToComponent(store) store.getPathToComponent = getPathToComponent(store)
store.addTemplatedComponent = addTemplatedComponent(store) store.addTemplatedComponent = addTemplatedComponent(store)
@ -258,7 +253,6 @@ const setCurrentScreen = store => screenName => {
) )
screen.props = safeProps screen.props = safeProps
s.currentComponentInfo = safeProps s.currentComponentInfo = safeProps
setCurrentPageFunctions(s)
return s return s
}) })
} }
@ -295,24 +289,6 @@ const savePage = store => async page => {
}) })
} }
const addStylesheet = store => stylesheet => {
store.update(s => {
s.pages.stylesheets.push(stylesheet)
_savePage(s)
return s
})
}
const removeStylesheet = store => stylesheet => {
store.update(state => {
state.pages.stylesheets = state.pages.stylesheets.filter(
s => s !== stylesheet
)
_savePage(state)
return state
})
}
const setCurrentPage = store => pageName => { const setCurrentPage = store => pageName => {
store.update(state => { store.update(state => {
const current_screens = state.pages[pageName]._screens const current_screens = state.pages[pageName]._screens
@ -338,7 +314,6 @@ const setCurrentPage = store => pageName => {
screen._css = generate_screen_css([screen.props]) screen._css = generate_screen_css([screen.props])
} }
setCurrentPageFunctions(state)
return state return state
}) })
} }
@ -424,7 +399,6 @@ const addTemplatedComponent = store => props => {
) )
regenerateCssForCurrentScreen(state) regenerateCssForCurrentScreen(state)
setCurrentPageFunctions(state)
_saveCurrentPreviewItem(state) _saveCurrentPreviewItem(state)
return state return state
@ -475,25 +449,6 @@ const setComponentStyle = store => (type, name, value) => {
}) })
} }
const setComponentCode = store => code => {
store.update(state => {
state.currentComponentInfo._code = code
setCurrentPageFunctions(state)
// save without messing with the store
_saveScreenApi(state.currentPreviewItem, state)
return state
})
}
const setCurrentPageFunctions = s => {
s.currentPageFunctions = buildPageCode(s.screens, s.pages[s.currentPageName])
insertCodeMetadata(s.currentPreviewItem.props)
}
const buildPageCode = (screens, page) => buildCodeForScreens([page, ...screens])
const setScreenType = store => type => { const setScreenType = store => type => {
store.update(state => { store.update(state => {
state.currentFrontEndType = type state.currentFrontEndType = type

View File

@ -10,7 +10,6 @@ const { join, resolve } = require("../centralPath")
const sqrl = require("squirrelly") const sqrl = require("squirrelly")
const { convertCssToFiles } = require("./convertCssToFiles") const { convertCssToFiles } = require("./convertCssToFiles")
const publicPath = require("./publicPath") const publicPath = require("./publicPath")
const deleteCodeMeta = require("./deleteCodeMeta")
module.exports = async (config, appId, pageName, pkg) => { module.exports = async (config, appId, pageName, pkg) => {
const appPath = appPackageFolder(config, appId) const appPath = appPackageFolder(config, appId)
@ -122,8 +121,6 @@ const savePageJson = async (appPath, pageName, pkg) => {
delete pkg.page._screens delete pkg.page._screens
} }
deleteCodeMeta(pkg.page.props)
await writeJSON(pageFile, pkg.page, { await writeJSON(pageFile, pkg.page, {
spaces: 2, spaces: 2,
}) })

View File

@ -1,9 +0,0 @@
module.exports = props => {
if (props._codeMeta) {
delete props._codeMeta
}
for (let child of props._children || []) {
module.exports(child)
}
}