Skip to content

Instantly share code, notes, and snippets.

View leonardfactory's full-sized avatar
Inventing

Leonardo Ascione leonardfactory

Inventing
View GitHub Profile
@leonardfactory
leonardfactory / sample-fp.js
Last active September 2, 2016 11:13
Data types in Flow
// Definition
export type Primitive = { type: string; };
// 'Factory'
export function Primitive(type:string) {
return {
type: string;
}
}
<?php
class PetsPlugin {
public boot() {
User::extend(function($model) {
// Evitiamo di salvare i 'pet_save_data' nel DB
$model->purgeable[] = ['pet_save_data'];
// Quando viene salvato un User, provvediamo a salvare anche il Pet correlato
$model->bindEvent('beforeSave', function($user) {
$pet = Pet::where('user_id', $user->id)->findOne();
/**
* Just a snippet, but it should work
*/
const {
roundedHeight,
height,
width
} = this.props;
const heightSq = Math.pow(roundedHeight - height, 2);
@leonardfactory
leonardfactory / context-with-hooks.tsx
Last active February 20, 2019 21:56
React Apollo & Hooks
// Let's define our context...
const ThemeContext = React.createContext(...);
// This component is nested in a `ThemeContext.Provider` node..
function MyComponent(props: Props) {
// No more HOCs!
const theme = useContext(ThemeContext);
// It's a kind of magic
return (
// HOC. Conterrà sia le proprietà del connect che quelle del componente in se
interface Props {}
function Component(props: Props) {
return ...;
}
export const ComponentConnected = connect(...)(Component);
// Hook. I dati del `connect` sono interni al Componente