From 62595c242169dc0c91be9a0fd0f26063fedfe496 Mon Sep 17 00:00:00 2001 From: Fawad Mirzad Date: Sat, 13 Feb 2021 18:58:41 +0100 Subject: [PATCH] Extract sting utility to an external function --- src/utils/bindProps.js | 12 ++++-------- src/utils/string.js | 5 +++++ 2 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 src/utils/string.js diff --git a/src/utils/bindProps.js b/src/utils/bindProps.js index cb888bc..593cec1 100644 --- a/src/utils/bindProps.js +++ b/src/utils/bindProps.js @@ -1,8 +1,5 @@ import WatchPrimitiveProperties from '../utils/WatchPrimitiveProperties' - -function capitalizeFirstLetter(string) { - return string.charAt(0).toUpperCase() + string.slice(1) -} +import {Str} from "./string"; export function getPropsValues(vueInst, props) { return Object.keys(props).reduce((acc, prop) => { @@ -26,8 +23,8 @@ export function bindProps(vueInst, googleMapsInst, props) { if (noBind) continue - const setMethodName = 'set' + capitalizeFirstLetter(attribute) - const getMethodName = 'get' + capitalizeFirstLetter(attribute) + const setMethodName = 'set' + Str.capitalizeFirstLetter(attribute) + const getMethodName = 'get' + Str.capitalizeFirstLetter(attribute) const eventName = attribute.toLowerCase() + '_changed' const initialValue = vueInst[attribute] @@ -42,8 +39,7 @@ export function bindProps(vueInst, googleMapsInst, props) { // although this may really be the user's responsibility if (type !== Object || !trackProperties) { // Track the object deeply - vueInst.$watch( - attribute, + vueInst.$watch(attribute, () => { const attributeValue = vueInst[attribute] diff --git a/src/utils/string.js b/src/utils/string.js new file mode 100644 index 0000000..830844d --- /dev/null +++ b/src/utils/string.js @@ -0,0 +1,5 @@ +export class Str { + static capitalizeFirstLetter(string) { + return string.charAt(0).toUpperCase() + string.slice(1) + } +}