Skip to content

Instantly share code, notes, and snippets.

View hanipcode's full-sized avatar
🎯
Focusing

Muhammad Hanif hanipcode

🎯
Focusing
View GitHub Profile
@hanipcode
hanipcode / CountryCodes.json
Last active January 20, 2017 12:31 — forked from Goles/CountryCodes.json
Country and Dial or Phone codes in JSON format
[
{
"name": "Afghanistan",
"dial_code": "+93",
"code": "AF"
},
{
"name": "Aland Islands",
"dial_code": "+358",
"code": "AX"
@hanipcode
hanipcode / formReducer.js
Created February 27, 2017 02:35
simple reducer with error using immutable data
const initialState = Map({
is_loading: false,
is_finish: null,
error: {
code: '',
message: '',
},
});
const formReducer = (state = initialState, action) => {
@hanipcode
hanipcode / renderError.js
Last active February 27, 2017 02:45
render error
//
// .... sisa aplikasi
//fungsi render
render() {
const { formReducer } = this.props;
// cek kalau field error ada isinya
const isError = formReducer.get('error').size > 0
// kalau mau render full page error atau redirect tinggal :
@hanipcode
hanipcode / rootApplication.js
Created February 27, 2017 03:06
error handling multiple error
// sisa dari aplikasi kita
//fungsi render
render() {
//alternative 1, mapping di render
const { formReducer, loginReducer, postReducer, errorList } = this.props;
//bisa di masukin array dulu sih kalau mau, tapi saya prefer ini
//karena masih reasonable untuk di stack di if
if (formReducer.get('error') ||
loginReducer.get('error') ||
@hanipcode
hanipcode / erorrReducer.js
Created February 27, 2017 03:25
redux real world example error reducer
const errorMessage = (state = null, action) => {
const { type, error } = action
if (type === ActionTypes.RESET_ERROR_MESSAGE) {
return null
} else if (error) {
return error
}
return state
@hanipcode
hanipcode / fetchActions.js
Created February 27, 2017 03:31
action yang diubah
export const succesFetch () {
// fungsi succes fetch
}
// here we put the magic. fungsi failedFetch
export const failedFetch(message) {
return {
type: FETCH.FAILED,
error: {
type: 'FETCH ERROR',
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
const request = require('request-promise');
function getPredictionList(searchQuery, key) {
const url = `https://maps.googleapis.com/maps/api/place/autocomplete/json?input=${searchQuery}&type=geocode&key=${key}`;
request(url)
.then(result => {
console.log(result);
})
.catch(err => console.log(err));
}
const request = require('request-promise');
function getPredictionList(searchQuery, key) {
const url = `https://maps.googleapis.com/maps/api/place/autocomplete/json?input=${searchQuery}&type=geocode&key=${key}`;
return request(url)
}
@hanipcode
hanipcode / services.js
Created September 26, 2017 11:01
fungsi getPlaceDetails
function getPlaceDetails(placeId, key) {
const url = `https://maps.googleapis.com/maps/api/place/details/json?placeid=${placeId}&key=${key}`;
return request(url);
}
getPlaceDetails('ChIJIe0SGpQNuC0RxXX30MzCZ2k', 'Your_api_key').then(result => {
console.log(result);
});