ember-polyfills / ember-factory-for-polyfill Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
The goal of this library is to provide a .factoryFor
implementation that is as close as possible to the one in Ember 2.12+. There are obviously some things that fall short (e.g. it is impossible to prevent double extend when using .factoryFor
in Ember versions prior to 2.12), but every attempt was made to be true to the original RFC.
I'd like to get some review on this from the following folks that were involved in the original implementation of this feature in Ember 2.12+:
The primary polyfill is located at vendor/ember-factory-for-polyfill/index.js.
This likely means some guards in this test to avoid erroring if owner._lookupFactory
is not present.
Current under Ember 2.12 we are triggering the owner._lookupFactory
deprecation. We should fix that and start throwing errors when a deprecation occurs (to ensure this library does not introduce deprecations).
Right now the Ember.getOwner
functionality in Ember < 2.3 is provided by ember-getowner-polyfill
. We could make that addon add the factoryFor
implementation, but it is slightly annoying since we'd have to duplicate a bunch of the test setup and whatnot.
Originally reported in emberjs/ember.js#15033 and testem/testem#1105.
This error is emitted from here when Testem tries to read value.nodeType
.
Error: You attempted to access "nodeType" on a factory manager created by container#factoryFor. "nodeType" is not a member of a factory manager.
at Object.get (index.js:27)
at derez (testem.js:70)
at derez (testem.js:108)
at derez (testem.js:108)
at derez (testem.js:108)
at derez (testem.js:99)
at derez (testem.js:108)
at decycle (testem.js:116)
at Object.serializeMessage (testem.js:906)
at Object.sendMessageToIframe (testem.js:840)
Offending line in Testem: public/testem/decycle.js#L67.
I'm unable to create a minimal reproduction scenario, but here are some findings:
// component => a class instance with cyclic references
// component.serialize() => a flat POJO
console.log(comment); // Works. Logs a class instance with cyclic dependencies.
console.log(comment.serialize()); // Works. Logs a flat POJO.
console.log(JSON.stringify(comment.serialize())); // Works, logs a string.
console.log(comment, comment.serialize()); // Crashes with the above error
console.log(comment, JSON.stringify(comment.serialize())); // Also crashes
PS You can't even imagine how frustrating this has been. The issue was appearing out of nowhere and then, after hours of frustration, disappearing into the blue. Every time I attributed the issue and fix to an unrelated change in my code. Testem trolled me into becoming one of those superstitious pigeons: I was resolving it by changing store.createRecord
to store.push
, by cleaning tmp/
and dist/
, etc.
I would never even consider that the console.log
invocation itself was the reason. My developer instinct was telling me to ignore it, believing it has no side effects. The stack trace never linked to the offending line, even with the Async
checkbox enabled.
This addon is outdated with the recent Ember versions
ember-factory-for-polyfill@^1.1.0:
version "1.1.2"
resolved "https://registry.yarnpkg.com/ember-factory-for-polyfill/-/ember-factory-for-polyfill-1.1.2.tgz#ea802002ec55154eea7be82abb586e77429be579"
dependencies:
ember-cli-babel "^5.1.7"
ember-cli-version-checker "^1.2.0"
$> ember -v
ember-cli: 2.14.1
node: 8.2.1
os: darwin x64
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.