You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
non-enumerable object properties are lost after passing an object to workerize. #34
// The main threadimportWorkerfrom'workerize-loader!./workers';importgetCompaniesFromFirebasefrom'./getCompaniesFromFirebase';constworker=Worker();const{
filterCompaniesByTypes
// Other modules}=worker;(async()=>{constcompanies=awaitgetCompaniesFromFirebase();// typeof companies[0].id === "string" // trueconstcompaniesFiltered=awaitfilterCompaniesByTypes(companies,['company-type-1','company-type-2']);// typeof companiesFiltered[0].id === "string" // false// typeof companiesFiltered[0].id === "undefined" // true})();
// The workerimportintersectionfrom'lodash/intersection';exportconstfilterCompaniesByTypes=(companies,typesToFilerBy)=>{returncompanies.filter(({ types, id })=>{// typeof id === 'undefined' // truereturnintersection(types,typesToFilerBy).length>0;});};
In the given example the getCompaniesFromFirebase() function returns an array of objects. Each object has some properties, inluding the id property that is non-enumerable.
After executing the filterCompaniesByTypes() function (which is a web worker function) I receive a filtered array. All id properties are gone.
if it's the desired behaviour (or an unpleasant, but expected, side-effect) not a bug, then it would be good to mention it in the readme.
Activity
philg-ygt commentedon Nov 13, 2019
Pretty sure the structured clone algorithm doesn't include non-enumerable properties of
Objects, so I wouldn't expect this to include them either.