Skip to content

Instantly share code, notes, and snippets.

View jadjoubran's full-sized avatar
Building learnjavascript.online & react-tutorial.app

Jad Joubran jadjoubran

Building learnjavascript.online & react-tutorial.app
View GitHub Profile
git clone git@github.com:jadjoubran/workbox-tutorial.git
cd workbox-tutorial
npm install
@jadjoubran
jadjoubran / API.js
Created November 17, 2017 13:50
Fetch wrapper for laravel-angular
class API{
constructur(){
//you could do advanced logic to determine the baseUrl
//based on the environment. Or you could simply pass it
//as an argument
this.baseUrl = 'http://laravel.dev/';//keep the slash at the end
}
fetch(url, options){
return fetch(`${this.baseUrl}${url}`, options);
@jadjoubran
jadjoubran / app.js
Created June 2, 2017 12:15
Promyfill example with async/await
async function run(){
//other application logic here
const fetchPolyfill = 'https://rawgit.com/github/fetch/master/fetch.js';
const fetchReady = await promyfill('fetch' in window, fetchPolyfill);
fetch('users.json');
const fetchPolyfill = 'https://rawgit.com/github/fetch/master/fetch.js';
const fetchReady = promyfill('fetch' in window, fetchPolyfill);
fetchReady.then(() => {
fetch('users.json');
});
//other application logic
@jadjoubran
jadjoubran / app.js
Created May 31, 2017 20:52
Promyfill updated demo
const fetchPolyfill = 'https://rawgit.com/github/fetch/master/fetch.js';
promyfill('fetch' in window, fetchPolyfill).then((fetch) => {
//fetch is available (polyfill is fetched only if needed)
fetch('users.json');
});
@jadjoubran
jadjoubran / app.js
Created May 4, 2017 15:07
Promyfill fetch demo
const fetchPolyfill = 'https://rawgit.com/github/fetch/master/fetch.js';
promyfill('fetch' in window, fetchPolyfill).then(() => {
//fetch is available (polyfill is fetched only if needed)
fetch('users.json');
});
@jadjoubran
jadjoubran / config.js
Created August 29, 2016 18:30
Enable production mode in angular
app.config(['$compileProvider', function ($compileProvider) {
$compileProvider.debugInfoEnabled(false);
}]);
@jadjoubran
jadjoubran / controller.js
Created August 29, 2016 11:12
Angular error interceptors
API.all('products').post({title, price}).then( (response) => {
var user = response.data.user;
}, (response) => {
//response.status
//response.data
});
@jadjoubran
jadjoubran / controller.js
Created August 29, 2016 11:12
Angular error interceptors
API.all('products').post({title, price}).then( (response) => {
var user = response.data.user;
});
@jadjoubran
jadjoubran / API.service.js
Created August 29, 2016 11:11
Angular error interceptors
export class APIService {
constructor(Restangular, ToastService) {
'ngInject';
var headers = {
'Content-Type': 'application/json',
'Accept': 'application/x.laravel.v1+json'
};
return Restangular.withConfig(function(RestangularConfigurer) {