This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(fn, ctx) { | |
if (!fn || !(fn instanceof Function)) throw Error('Invalid arguments'); | |
return function() { | |
const _args = Array.from(arguments); | |
var promiseFn = function(resolve, reject) { | |
_args.push(function(err, data) { | |
if (err) return reject(err); | |
return resolve(data); | |
}); | |
fn.apply(ctx, _args); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApiRequest { | |
all(requests) { | |
return Rx.Observable.forkJoin(...requests); | |
} | |
... | |
} | |
var apiRequest = new ApiRequest(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApiRequest { | |
observableRequest(url) { | |
return Rx.Observable.fromPromise(this.__makeRequest(url, 'GET')); | |
} | |
__makeRequest(url, method) { | |
return new Promise((resolve, reject) => { | |
let xhr = new XMLHttpRequest(); | |
Rx.Observable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function OrMatchFilter() { | |
return function(elements, filterData, matchExact) { | |
if(//we have no elements, return empty | |
!elements || elements.length === 0) return []; | |
if(//filter data is not defined or is an empty object | |
!filterData || (Object.keys(filterData).length === 0 && filterData.constructor === Object)) return elements; | |
function decoupleObjectKeys(obj) { | |
var arrayOfKeys = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public getForecast(days: number) { | |
// Parameters obj- | |
let params: URLSearchParams = new URLSearchParams(); | |
params.set('appid', StaticSettings.API_KEY); | |
params.set('cnt', days.toString()); | |
//Http request- | |
return this.http.get(StaticSettings.BASE_URL, { | |
search: params | |
}).subscribe( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.app('testing', []) | |
.constant(‘baseSettings’, {}) | |
.value('appSettings', {}) | |
.controller('MainCtrl', function($scope, appSettings){ | |
$scope.$watch(function(){ return appSettings; }, function(old, _new){ | |
//your code here… | |
}); | |
}) | |
.controller('AnotherCtrl', function($scope , SettingsHelper){ | |
SettingsHelper.setSetting('enableToPerform', true); |