This file contains 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
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 }); |
This file contains 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
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); | |
} | |
} |
This file contains 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
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]; | |
} |
This file contains 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
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 ( |
This file contains 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 MyForm extends Component { | |
render() { | |
let { formData, onSubmitForm } = this.props; | |
return ( | |
<View> | |
<TextInput value={formData.name} /> | |
<TextInput value={formData.email} /> |
This file contains 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
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: "" | |
} |