reduce payload sent for storage

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

@ -1,8 +1,9 @@
import axios from 'axios' import axios from 'axios'
import debounce from 'lodash.debounce' import debounce from 'lodash.debounce'
import omitBy from 'lodash.omitby'
import ms from 'ms' import ms from 'ms'
import { DEFAULT_CODE } from './constants' import { DEFAULT_CODE, DEFAULT_SETTINGS } from './constants'
import { fileToDataURL } from './util' 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) { function updateSnippet(uid, state) {
const sanitized = omitBy(state, isNotDefaultSetting)
const data = { const data = {
...state, ...sanitized,
code: state.code != null ? state.code : DEFAULT_CODE code: state.code != null ? state.code : DEFAULT_CODE
} }
if (uid) { if (uid) {
return client return client
.patch(`/snippets/${uid}`, data) .patch(`/snippets/${uid}`, data)

Loading…
Cancel
Save