From 520e19ab44065622a7a47c22d60ccd70de0e68bc Mon Sep 17 00:00:00 2001 From: Mike Fix Date: Wed, 21 Aug 2019 10:21:40 -0700 Subject: [PATCH] reduce payload sent for storage --- lib/api.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/api.js b/lib/api.js index 9309812..e01eb61 100644 --- a/lib/api.js +++ b/lib/api.js @@ -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)