diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a9e843..393a3e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to `react-cookify` will be documented in this file. +## v0.3.4-beta.1 - 2022-01-08 + +- Bump @rollup/plugin-typescript from 10.0.1 to 11.0.0 +- Removed `changeDataState()` and directly integrated the code in `actionCheckbox()` +- Removed `setMemoryDataWithChange()` and directly integrated the code in `actionCheckbox()` +- Added script `build:watch` for development +- Modified `handleConsentObjectChange()` to fix the issue of [#2](https://github.com/Jersyfi/react-cookify/issues/2) + ## v0.2.1-beta.1 - 2022-01-07 - Added `@rollup/plugin-terser` to minify and compress the code in build process diff --git a/package.json b/package.json index 6c6228f..e624233 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { "name": "react-cookify", - "version": "0.2.1-beta.1", + "version": "0.3.4-beta.1", "description": "Simple, customizable open source cookie consent banner for GDPR law", "scripts": { "lint": "eslint src/**/*.{js,jsx,ts,tsx,json}", - "build": "rollup -c --bundleConfigAsCjs" + "build": "rollup -c --bundleConfigAsCjs", + "build:watch": "rollup -c --bundleConfigAsCjs -w" }, "repository": { "type": "git", diff --git a/src/context/useCookify.tsx b/src/context/useCookify.tsx index bf6e8ab..3273d9d 100644 --- a/src/context/useCookify.tsx +++ b/src/context/useCookify.tsx @@ -60,35 +60,6 @@ export const useCookify = (options: CookifyOptionsType) => { ) } - /** - * Set memory data with change - */ - const setMemoryDataWithChange = () => { - if (_this.saveWithChange === true) { - setMemoryData() - handleConsentTrackingChange() - } - } - - /** - * Changes the cookie state and saves the data - * - * @param {string} type - * @param {boolean} value - */ - const changeDataState = (type: string, value: boolean) => { - const newConsentObjectViewed: boolean = consentObject.viewed - const newConsentObjectData: ConsentObjectDataType = consentObject.data - - newConsentObjectData[type] = value - - handleConsentObjectChange({ - viewed: newConsentObjectViewed, - data: newConsentObjectData - }) - setMemoryDataWithChange() - } - /** * Event Listeners */ @@ -111,8 +82,20 @@ export const useCookify = (options: CookifyOptionsType) => { * @param {string} type */ const actionCheckbox = (type: string) => { - changeDataState(type, !consentObject.data[type]) - setMemoryDataWithChange() + const newConsentObjectViewed: boolean = consentObject.viewed + const newConsentObjectData: ConsentObjectDataType = consentObject.data + + newConsentObjectData[type] = !consentObject.data[type] + + handleConsentObjectChange({ + viewed: newConsentObjectViewed, + data: newConsentObjectData + }) + + if (_this.saveWithChange === true) { + setMemoryData() + handleConsentTrackingChange() + } } /** @@ -185,10 +168,7 @@ export const useCookify = (options: CookifyOptionsType) => { const [consentTracking, setConsentTracking] = useState(0) const handleConsentObjectChange = (newConsentObject: ConsentObjectType) => { - setConsentObject(prevConsentObject => ({ - ...prevConsentObject, - newConsentObject - })) + setConsentObject(newConsentObject) } const handleConsentDisplayedChange = (newConsentDisplayed: boolean) => {