[ 
https://issues.apache.org/jira/browse/CB-13179?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16617197#comment-16617197
 ] 

ASF GitHub Bot commented on CB-13179:
-------------------------------------

janpio commented on issue #215: CB-13179:(all) invoke onEvent listener with 
_realReader as applyThis
URL: 
https://github.com/apache/cordova-plugin-file/pull/215#issuecomment-421924223
 
 
   Yes, it seems to be some formatting things for now:
   
   ```
   cordova-plugin-file/www/FileReader.js
   139:72error  Strings must use singlequotequotes
   139:92error  Missing space before value for key 'loaded'key-spacing
   139:114error  Missing space before value for key 'total'key-spacing
   159:68error  Strings must use singlequotequotes
   159:84error  Missing space before value for key 'target'key-spacing
   163:71error  Strings must use singlequotequotes
   163:90error  Missing space before value for key 'target'key-spacing
   182:65error  Strings must use singlequotequotes
   182:82error  Missing space before value for key 'target'key-spacing
   186:67error  Strings must use singlequotequotes
   186:86error  Missing space before value for key 'target'key-spacing
   207:82error  Missing space before value for key 'target'key-spacing
   211:86error  Missing space before value for key 'target'key-spacing
   ```
   
   Run locally with `npm run eslint`.
   
   But there are also actual test failures later on:
   
   ```
   ✗ file.spec.106 should be able to write a File to a FileWriter
   -writer.onerror - Error writing content on file: verify.txt
   
{"type":"error","bubbles":false,"cancelBubble":false,"cancelable":false,"lengthComputable":false,"loaded":0,"total":0,"target":{"fileName":"","length":0,"localURL":"file:///persistent/verify.txt","position":0,"readyState":2,"result":null,"error":{"code":9},"onwritestart":null,"onprogress":null,"onwrite":null,"onabort":null}}
   ✗ file.spec.107 should be able to write a sliced File to a FileWriter
   -Expected 0 to be 40.
   -Expected 0 to be 40.
   -writer.onerror - Error writing content on file: verify2.txt
   
{"type":"error","bubbles":false,"cancelBubble":false,"cancelable":false,"lengthComputable":false,"loaded":0,"total":0,"target":{"fileName":"","length":0,"localURL":"file:///persistent/verify2.txt","position":0,"readyState":2,"result":null,"error":{"code":9},"onwritestart":null,"onprogress":null,"onwrite":null,"onabort":null}}
   ✗ file.spec.108 should be able to write binary data from a File
   -Expected 0 to be 10.
   -Expected 0 to be 10.
   -writer.onerror - Error writing content on file: verify.bin
   
{"type":"error","bubbles":false,"cancelBubble":false,"cancelable":false,"lengthComputable":false,"loaded":0,"total":0,"target":{"fileName":"","length":0,"localURL":"file:///persistent/verify.bin","position":0,"readyState":2,"result":null,"error":{"code":9},"onwritestart":null,"onprogress":null,"onwrite":null,"onabort":null}}
         1.1.13 Backwards compatibility
   ✗ file.spec.109 should be able to resolve a file:/// URL
   -Expected 0 to be 32.
   -Expected 0 to be 32.
   ```
   
   You run those with `npm test`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Cordova file plugin onEvent(such as onload) should be invoked with 
> _realReader as this
> --------------------------------------------------------------------------------------
>
>                 Key: CB-13179
>                 URL: https://issues.apache.org/jira/browse/CB-13179
>             Project: Apache Cordova
>          Issue Type: Improvement
>          Components: cordova-plugin-file
>         Environment: Android, ios, Browser
>            Reporter: Jia Li
>            Priority: Minor
>              Labels: features
>
> When `FileReader` add onEvent listener such as `onload`, it will add the 
> listener to inner `_realReader` , but when it invoke the listener, it use the 
> FileReader as `this`.
> 1. When add onload listener in application code.
> ```javascript
> var fileReader = new FileReader();
> fileReader.onload = function() {};
> ```
> it will call `www/FileReader.js defineEvent`
> ```javascript
> function defineEvent(eventName) {
>     utils.defineGetterSetter(FileReader.prototype, eventName, function() {
>         return this._realReader[eventName] || null;
>     }, function(value) {
>         this._realReader[eventName] = value;
>     });
> }
> ```  
> the listener is added to `this._realReader`.
> And when the listener is triggered for example in `readSuccessCallback`
> it will invoke the method with `this`.
> ```javascript
> this.onload(new ProgressEvent("load", {target:this}));
> ```
> in the normal senario, it will ok, but when it work with some polyfilles such 
> as `zone.js of angular4`, it will fail because `zone.js` have some special 
> handling which require the `this` object be the same when add listener and 
> invoke listener.
> https://github.com/angular/zone.js/issues/868



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org
For additional commands, e-mail: issues-h...@cordova.apache.org

Reply via email to