Skip to content

Commit

Permalink
Merge pull request #37 from ember-polyfills/bugfix/better-patch
Browse files Browse the repository at this point in the history
[BUGFIX] Better Data Patch
  • Loading branch information
Chris Garrett authored Mar 25, 2020
2 parents c0f03e5 + 4e8fe65 commit 9cc68c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@
"ember-addon": {
"configPath": "tests/dummy/config",
"after": [
"ember-source",
"ember-classic-decorator"
"ember-source"
]
}
}
23 changes: 7 additions & 16 deletions vendor/ember-decorators-polyfill/data-fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
);
}

let mainRequire = require;

function computedMacroWithOptionalParams(fn) {
return (...maybeDesc) =>
(isFieldDescriptor(maybeDesc)
Expand All @@ -28,16 +26,9 @@
let DS;

try {
DS = mainRequire('ember-data').default;
DS = window.requirejs('ember-data').default;
} catch (e) {
return mainRequire(moduleName);
}

if (window.require !== patchDataDecorators) {
// Something else patched, most likely ember-classic-decorator
// and since we're about to do things we shouldn't, get the original
// require back
mainRequire = window.require;
return window.requirejs(moduleName);
}

let {
Expand All @@ -54,19 +45,19 @@
DS.belongsTo = belongsTo;
DS.hasMany = hasMany;

if (mainRequire.entries['@ember-data/model/index']) {
if (window.requirejs.entries['@ember-data/model/index']) {
let newExports = Object.assign(
{},
mainRequire.entries['@ember-data/model/index'].module.exports,
window.requirejs.entries['@ember-data/model/index'].module.exports,
{ attr, belongsTo, hasMany }
);

mainRequire.entries['@ember-data/model/index'].module.exports = newExports;
window.requirejs.entries['@ember-data/model/index'].module.exports = newExports;
}

window.require = require = mainRequire;
window.require = require = window.requirejs;

return mainRequire(moduleName);
return window.requirejs(moduleName);
}
})();

0 comments on commit 9cc68c2

Please sign in to comment.