developit / developit/workerize
non-enumerable object properties are lost after passing an object to workerize.
- 主要語言
- JavaScript
- 星號
- 4.4k
- 分支
- 87
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Here's a real life example:
``` js
// 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
})();
```
``` js
// 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.
貢獻指南
這個儲存庫沒有索引到貢獻指南
研究方向
從 workerize-loader 範例開始,重現 Firebase 物件與篩選結果之間所回報的差異。檢查 worker 呼叫邊界和 README,以判斷保留不可列舉屬性是否為預期行為。完成標準是:要麼在呼叫過程中保留 id 屬性,要麼清楚地記錄觀察到的行為。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- javascript
- 領域
- web-dev
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100