Gathering detailed insights and metrics for angular-oboe
Gathering detailed insights and metrics for angular-oboe
Gathering detailed insights and metrics for angular-oboe
Gathering detailed insights and metrics for angular-oboe
npm install angular-oboe
Typescript
Module System
Node Version
NPM Version
73.8
Supply Chain
98.5
Quality
74.9
Maintenance
100
Vulnerability
100
License
JavaScript (63.2%)
HTML (35.46%)
CSS (1.34%)
Total Downloads
12,496
Last Day
1
Last Week
6
Last Month
36
Last Year
1,027
MIT License
65 Stars
113 Commits
16 Forks
8 Watchers
2 Branches
7 Contributors
Updated on Apr 03, 2024
Latest Version
0.6.0
Package Id
angular-oboe@0.6.0
Size
3.21 MB
NPM Version
3.3.6
Node Version
5.0.0
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
100%
6
Compared to previous week
Last Month
-47.8%
36
Compared to previous month
Last Year
37.9%
1,027
Compared to previous year
A service to stream JSON data to an array in your controller by using the Oboe.js library.
This repo is for distribution on bower
.
Many thanks to Jim Higson for the oboe.js library. See http://www.oboejs.com
The Oboe service collects a datastream and tries to parse the data as JSON objects. You can pass a URL and a pattern to the service, which will return a promise. By processing the notification immediately in your scope, the user will experience your application as very fast, especially on mobile.
The module takes advantage of the defer and promise implementation of Angular and the Oboe.js library. The Oboe library parses the JSON stream and recognizes the nodes which meets the criteria in the supplied pattern. The module then collects the JSON objects and notifies the promise of the new node.
Make sure you have the following installed:
1git clone https://github.com/RonB/angular-oboe.git 2cd angular-oboe 3npm install 4bower install 5grunt
Now go to a browser and visit http://localhost:9000
bower
Go to your project folder and run
1bower install angular-oboe --save
Add a <script>
to your index.html
:
1<script src="/bower_components/oboe/dist/oboe-browser.min.js"></script> 2<script src="/bower_components/angular-oboe/dist/angular-oboe.min.js"></script>
And add ngOboe
module to your app:
1angular.module('myApp', ['ngOboe']);
In your controller you add data to your scope by calling the Oboe service. This returns a promise. The service is called with an object that contains the parameters for the Oboe service. They are the same as the oboe.js API [http://oboejs.com/api].
specify the url from which the json data should be read
The pattern is to select JSON objects that meet that pattern. http://oboejs.com/api#pattern-matching
Callback function which is called when the stream starts with a handle to the stream as a parameter. The stream has several functions and events. i.e: If you want to abort the stream while loading you can call the abort() method (http://oboejs.com/api#-abort-).
Callback function which is called when the stream ends or, if your datastream is not closed but streams multiple JSON objects, then this function is called every time a JSON object is parsed, with the parsed JSON as a parameter.
To use the data in your controller you call the 'then' function of the returned promise.
You can pass three functions:
1angular.module('MyApp') 2 .controller(['$scope', 'Oboe', function($scope, Oboe) { 3 $scope.myData = []; 4 Oboe({ 5 url: '/api/myData', 6 pattern: '{index}', 7 start: function(stream) { 8 // handle to the stream 9 $scope.stream = stream; 10 $scope.status = 'started'; 11 }, 12 done: function(JSON) { 13 $scope.status = 'done'; 14 } 15 }).then(function() { 16 // promise is resolved 17 }, function(error) { 18 // handle errors 19 }, function(node) { 20 // node received 21 $scope.myData.push(node); 22 if($scope.myData.length === 1000) { 23 $scope.stream.abort(); 24 alert('The maximum of one thousand records reached'); 25 } 26 }); 27 }]);
The entire parameter object will be passed to the Oboe funtion [http://oboejs.com/api]. Use this to accomplish authentication with the backend:
1angular.module('MyApp') 2 .controller(['$scope', 'Oboe', function($scope, Oboe) { 3 $scope.myData = []; 4 Oboe({ 5 url: '/api/myData', 6 pattern: '{index}', 7 withCredentials: true, 8 headers: { 9 Authentication: 'Basic ' + btoa('yourusername:yourpassword') 10 } 11 }).then(function() { 12 // promise is resolved 13 }, function(error) { 14 // handle errors 15 }, function(node) { 16 // node received 17 $scope.myData.push(node); 18 }); 19 }]);
Parsing the entire datastream might take longer if the JSON is served in one chunk because parsing the data in JS is slower than the standard native parsing in the browser. It might use more CPU than desired in that case.
This factory is in a very early stage. Still to do:
Contributers to the project are very welcome!
The MIT License
Copyright (c) 2010-2012 Google, Inc. http://angularjs.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.