Drop file here...My code is:...">

RxJS: How can I event event.preventDefault () delete an event?

My markup:

<section id="drop-target"> Drop file here... </section> 

My code is:

 var dropTarget = document.getElementById('drop-target'); Rx.Observable.fromEvent(dropTarget, 'dragover').subscribe(function(event) { event.preventDefault(); }); var dropStream = Rx.Observable.fromEvent(dropTarget, 'drop'); dropStream.subscribe(function(event) { console.log('This will be called.'); event.preventDefault(); }); dropStream.map(function(event) { console.log('This will not be called.'); return event.dataTransfer.files[0].path; }); 

Any ideas on how to call my last map callback? I need preventDefault for drop and dragover so that the browser does not open the file.

+6
source share
1 answer

You just need to subscribe to the map stream. All map this creates a new observable that will trigger the map operation in the stream. But you still need to sign up to get something done:

 dropStream .map(function (event) { console.log("hello"); return event.dataTransfer.files[0].path; }) .subscribe(function (path) { console.log("path=" + path); }); 
+6
source

Source: https://habr.com/ru/post/981747/


All Articles