You will get back an object that has the regular methods (get, set, remove). The object contains also an attributes property that by default has the value {path: '/'}. If you then call
Cookies.set('name', 'value');
the cookie's path will be /.
If then we would do:
Cookies = Cookies.withConverter({ write: function () { .... } });
Cookies.set('name', 'value');
The cookie's path will still be / in this case. js-cookie is supporting this scenario here. Pay attention that the code uses this.attributes.
We then call in the Audience module cookieJar.withConverter. At this point, we will get back as instance without the default path being /. That happens because the this.attributes in js-cookie code will refer to the object that we export in the cookieJar.js file. And that object doesn't contain any attributes property.
Initially I was thinking to just export the js-cookie module inside cookieJar.js. The cookieJar code would have become something like this:
import cookie from "js-cookie";
export default cookie;
There is a problem though. The Cookies variable that is imported is an object that contains 2 properties: attributes and converter.
The methods get, set and remove are set on the prototype chain of that object.
the spread operation is working only on the properties. Not on the whole prototype chain. The result was that you would have got back an object that didn't contain get or remove properties anymore. This is why I got to the solution that Jon suggested to bind the js-cookie initial context.
Description
You will get back an object that has the regular methods (
get
,set
,remove
). The object contains also anattributes
property that by default has the value{path: '/'}
. If you then callthe cookie's path will be
/
.The cookie's path will still be
/
in this case. js-cookie is supporting this scenario here. Pay attention that the code usesthis.attributes
.We then call in the Audience module
cookieJar.withConverter
. At this point, we will get back as instance without the default path being/
. That happens because thethis.attributes
in js-cookie code will refer to the object that we export in thecookieJar.js
file. And that object doesn't contain any attributes property.cookieJar.js
. The cookieJar code would have become something like this:There is a problem though. The
Cookies
variable that is imported is an object that contains 2 properties:attributes
andconverter
.The methods
get
,set
andremove
are set on the prototype chain of that object.And when we do here
the spread operation is working only on the properties. Not on the whole prototype chain. The result was that you would have got back an object that didn't contain
get
orremove
properties anymore. This is why I got to the solution that Jon suggested to bind the js-cookie initial context.Related Issue
https://jira.corp.adobe.com/browse/PLATIR-42315
Motivation and Context
Screenshots (if appropriate):
Types of changes
Checklist: