Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non-enumerable object properties are lost after passing an object to workerize. #34

Open
wujekbogdan opened this issue Sep 25, 2018 · 1 comment

Comments

@wujekbogdan
Copy link

Here's a real life example:

// The main thread
import Worker from 'workerize-loader!./workers';
import getCompaniesFromFirebase from './getCompaniesFromFirebase';

const worker = Worker();

const {
  filterCompaniesByTypes
  // Other modules
} = worker;

(async () => {
  const companies = await getCompaniesFromFirebase();
  // typeof companies[0].id === "string" // true

  const companiesFiltered = await filterCompaniesByTypes(companies, ['company-type-1', 'company-type-2']);
  // typeof companiesFiltered[0].id === "string" // false
  // typeof companiesFiltered[0].id === "undefined" // true
})();
// The worker
import intersection from 'lodash/intersection';

export const filterCompaniesByTypes = (companies, typesToFilerBy) => {
  return companies.filter(({ types, id }) => {
    // typeof id === 'undefined' // true
    return intersection(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.

@philg-ygt
Copy link

Pretty sure the structured clone algorithm doesn't include non-enumerable properties of Objects, so I wouldn't expect this to include them either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants