Reactive-Extensions/rxjs-jquery là dự án JavaScript với 210 sao. Reactive Extensions bindings for jQuery
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
RxJS-jQuery 1.1 - jQuery Bindings for the Reactive Extensions for JavaScript
OVERVIEW
This project provides Reactive Extensions for JavaScript (RxJS) bindings for jQuery to abstract over the event binding, Ajax and Deferreds. The RxJS libraries are not included with this release and must be installed separately.
GETTING STARTED
There are a number of ways to get started with the jQuery Bindings for RxJS. The files are available on cdnjs and jsDelivr.
Download the Source
To download the source of the jQuery Bindings for the Reactive Extensions for JavaScript, type in the following:
git clone https://github.com/Reactive-Extensions/rxjs-jquery.git
cd ./rxjs-jquery
Installing with NPM
npm install rx-jquery
Installing with Bower
bower install rxjs-jquery
Installing with Jam
jam install rx-jquery
Installing with NuGet
PM> Install-Package RxJS-Bridges-jQuery
Getting Started with the jQuery Bindings
Let's walk through a simple yet powerful example of the Reactive Extensions for JavaScript Bindings for jQuery, autocomplete. In this example, we will take user input from a textbox and trim and throttle the input so that we're not overloading the server with requests for suggestions.
We'll start out with a basic skeleton for our application with script references to jQuery, RxJS, RxJS Time-based methods, and the RxJS Bindings for jQuery, along with a textbox for input and a list for our results.
The goal here is to take the input from our textbox and throttle it in a way that it doesn't overload the service with requests. To do that, we'll get the reference to the textInput using jQuery, then bind to the 'keyup' event using the keyupAsObservable method which then takes the jQuery object and transforms it into an RxJS Observable.
var throttledInput = $('#textInput')
.keyupAsObservable()
Since we're only interested in the text, we'll use the map method to take the event object and return the target's value.
.map( function (ev) {
return $(ev.target).val();
})
We're also not interested in query terms less than two letters, so we'll trim that user input by using the filter method returning whether the string length is appropriate.
.filter( function (text) {
return text.length > 2;
})
We also want to slow down the user input a little bit so that the external service won't be flooded with requests. To do that, we'll use the throttle method with a timeout of 500 milliseconds, which will ignore your fast typing and only return a value after you have paused for that time span.
.throttle(500 /* ms */)
Lastly, we only want distinct values in our input stream, so we can ignore requests that are not unique, for example if I copy and paste the same value twice, the request will be ignored.
.distinctUntilChanged();
Putting it all together, our throttledInput looks like the following:
var throttledInput = $('#textInput')
.keyupAsObservable()
.map( function (ev) {
return $(ev.target).val();
})
.filter( function (text) {
return text.length > 2;
})
.throttle(500)
.distinctUntilChanged();
Now that we have the throttled input from the textbox, we need to query our service, in this case, the Wikipedia API, for suggestions based upon our input. To do this, we'll create a function called searchWikipedia which calls the jQuery.ajaxAsObservable method which wraps the existing jQuery Ajax request in an Rx.AsyncSubject.
Now that the Wikipedia Search has been wrapped, we can tie together throttled input and our service call. Finally, to deal with concurrency issues, we'll need to ensure we're getting only the latest value. Issues can arise with asynchronous programming where an earlier value, if not cancelled properly, can be returned before the latest value is returned, thus causing bugs. To ensure that this doesn't happen, we have the flatMap method which returns only the latest value.
var suggestions = throttledInput.flatMapLatest( function (text) {
return searchWikipedia(text);
});
Finally, we'll subscribe to our observable by calling subscribe which will receive the results and put them into an unordered list. We'll also handle errors, for example if the server is unavailable by passing in a second function which handles the errors.
var selector = $('#results');
var subscription = suggestions.subscribe(
function (data) {
selector.clear();
$.each(data[1], function (_, text) {
$('<li>' + text + '</li>').appendTo(selector);
});
},
function (e) {
selector.clear();
$('<li>Error: ' + e + '</li>').appendTo('#results');
}
);
We've only scratched the surface of this library in this simple example.
Implemented Bindings
jQuery Events
bind - bindAsObservable
delegate - delegateAsObservable
live - liveAsObservable
on - onAsObservable
one - oneAsObservable
jQuery Event Shortcuts
change - changeAsObservable
click - clickAsObservable
dblclick - dblclickAsObservable
focus - focusAsObservable
focusin - focusinAsObservable
focusout - focusoutAsObservable
hover - hoverAsObservable
keydown - keydownAsObservable
keypress - keypressAsObservable
keyup - keyupAsObservable
load - loadAsObservable
mousedown - mousedownAsObservable
mouseenter - mouseenterAsObservable
mouseleave - mouseleaveAsObservable
mousemove - mousemoveAsObservable
mouseout - mouseoutAsObservable
mouseover - mouseoverAsObservable
mouseup - mouseupAsObservable
ready - readyAsObservable
resize - resizeAsObservable
scroll - scrollAsObservable
select - selectAsObservable
submit - submitAsObservable
unload - unloadAsObservable
jQuery Effects
animate - animateAsObservable
fadeIn - fadeInAsObservable
fadeOut - fadeOutAsObservable
fadeTo - fadeToAsObservable
fadeToggle - fadeToggleAsObservable
hide - hideAsObservable
show - showAsObservable
slideDown - slideDownAsObservable
slideToggle - slideToggleAsObservable
slideUp - slideUpAsObservable
Ajax Methods
ajax - $.ajaxAsObservable
get - $.getAsObservable
getJSON - $.getJSONAsObservable
getScript - $.getScriptAsObservable
post - $.postAsObservable
$.Deferred
Deferred.toObservable
Rx.Observable.toDeferred
$.Callbacks
Callbacks.toObservable
Contributing
There are lots of ways to contribute to the project, and we appreciate our contributors.
You can contribute by reviewing and sending feedback on code checkins, suggesting and trying out new features as they are implemented, submit bugs and help us verify fixes as they are checked in, as well as submit code fixes or code contributions of your own. Note that all code submissions will be rigorously reviewed and tested by the Rx Team, and only those that meet an extremely high bar for both quality and design/roadmap appropriateness will be merged into the source.
License
Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
Microsoft Open Technologies would like to thank its contributors.
Licensed under the Apache License, Version 2.0 (the "License"); you
may not use this file except in compliance with the License. You may
obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing permissions
and limitations under the License.
Đọc thêm về Reactive-Extensions/rxjs-jquery ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/Reactive-Extensions/rxjs-jquery là nguồn chính thức.
Reactive-Extensions/rxjs-jquery có bao nhiêu sao?
Reactive-Extensions/rxjs-jquery có 210 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/Reactive-Extensions/rxjs-jquery. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
Reactive-Extensions/rxjs-jquery có phải mã nguồn mở không?
TopGit chưa ghi nhận license cho Reactive-Extensions/rxjs-jquery. Phần lớn repo public trên GitHub là mã nguồn mở, nhưng điều khoản khác nhau từng repo — mở file LICENSE để xác nhận.
Reactive-Extensions/rxjs-jquery có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho Reactive-Extensions/rxjs-jquery. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
Reactive-Extensions/rxjs-jquery có trang demo không?
Dự án có trang chủ ở http://reactive-extensions.github.com/rxjs-jquery. Tab "Readme" ở trang này thường có ảnh chụp và hướng dẫn bắt đầu nhanh.
Reactive-Extensions/rxjs-jquery còn đang phát triển không?
Commit gần nhất trên Reactive-Extensions/rxjs-jquery là 10.4 năm trước (theo timestamp GitHub). Repo có 36 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
Đọc đầy đủ README ở tab phía trên.
rxjs-jquery có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về rxjs-jquery.