reduce payload sent for storage

main
Mike Fix 5 years ago
parent 068ad43937
commit 520e19ab44

@ -1,8 +1,9 @@
import axios from 'axios'
import debounce from 'lodash.debounce'
import omitBy from 'lodash.omitby'
import ms from 'ms'
import { DEFAULT_CODE } from './constants'
import { DEFAULT_CODE, DEFAULT_SETTINGS } from './constants'
import { fileToDataURL } from './util'
@ -82,11 +83,18 @@ function getSnippet(uid, { host } = {}) {
})
}
function isNotDefaultSetting(v, k) {
return v === DEFAULT_SETTINGS[k] || !Object.prototype.hasOwnProperty.call(DEFAULT_SETTINGS, k)
}
function updateSnippet(uid, state) {
const sanitized = omitBy(state, isNotDefaultSetting)
const data = {
...state,
...sanitized,
code: state.code != null ? state.code : DEFAULT_CODE
}
if (uid) {
return client
.patch(`/snippets/${uid}`, data)

Loading…
Cancel
Save