Skip to content

Instantly share code, notes, and snippets.

View asmyk's full-sized avatar

asmyk asmyk

View GitHub Profile
@asmyk
asmyk / rn-form-example.js
Created March 12, 2018 10:36
Example of standard react-native form component with state
import React, { Component } from 'react';
import { StyleSheet, Text, TextInput, View, Button } from 'react-native';
class MyForm extends Component {
constructor(props) {
super(props);
this.state = {
name: "",
email: ""
}
@asmyk
asmyk / rn-simple-composed-form.js
Created March 12, 2018 11:31
React native form example with recompose
class MyForm extends Component {
render() {
let { formData, onSubmitForm } = this.props;
return (
<View>
<TextInput value={formData.name} />
<TextInput value={formData.email} />
@asmyk
asmyk / rn-form-validation-example.js
Last active March 19, 2018 08:59
Validation form example with recompose
import React, { Component } from 'react';
import { compose, withHandlers, withProps, withState, withStateHandlers } from "recompose";
import { StyleSheet, Text, TextInput, View, Button } from 'react-native';
import { withFormData, withFormHandlers } from "./withFormData";
class MyForm extends Component {
render() {
let { formData: { name, age }, sendForm, updateFormData, formErrors } = this.props;
return (
@asmyk
asmyk / rn-withFormData.js
Last active March 19, 2018 08:59
React native form data HOC
import { compose, withHandlers, withProps, withState, withStateHandlers } from "recompose";
function validateField(value, rules) {
for (let rule in rules) {
isRulePassed = rules[rule][0](value);
if (!isRulePassed) {
return rules[rule][1];
}
@asmyk
asmyk / angular-sample-service.ts
Last active July 2, 2018 17:44
This is an example angular service
export class UsersService {
constructor(private http: HttpClient) { }
getUsers() {
// let's assume that we have same method names on local and prod
const method = "/users";
return this.http.get(method);
}
}
export class UrlInterceptor implements HttpInterceptor {
constructor(private configService: ConfigService) { }
intercept(req: HttpRequest<any>, next: HttpHandler):
Observable<HttpEvent<any>> {
// get API url depending on actual enviroment(prod, local etc)
const api_url = this.configService.getApiUrl();
// concat method name with API url
const request_url = api_url + req.url;
const intercepted = req.clone({ url: request_url });