Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using Elixir-Style Modules in JavaScript
import React from ‘react’;
import {userType, fullName} from ./user’;
const UserComponent = user => (
<div>Name: {fullName(user)}</div>
);
UserComponent.propTypes = {
user: userType
};
import React from ‘react’;
import * as User from ./user’;
const UserComponent = user => (
<div>Name: {User.fullName(user)}</div>
);
UserComponent.propTypes = {
user: User.t
};
import * as User from './user';
class UserComponent {
name(): User.t {
return User.fullName(this.user);
}
}
import { userToFriend } from 'accounts/User';
userToFriend(user):
export const userType = PropTypes.shape({
firstName: PropTypes.string;
lastName: PropTypes.string;
email: PropTypes.string;
});
export function fullName(user) {
return `${user.firstName} ${user.lastName}`;
}
import * as User from 'accounts/User';
User.toFriend(user):
defmodule User do
defstruct [:first_name, :last_name, :email]
def full_name(user = %User{}) do
"#{user.first_name} #{user.last_name}
end
end
/**
* @typedef {Object} User
* @property {string} firstName
* @property {string} lastName
* @property {string} email
*/
/**
* @param {User} user
* @returns {string}
*/
export function fullName(user) {
return `${user.firstName} ${user.lastName}`;
}
export interface User {
firstName: string;
lastName: string;
email: string;
}
export function fullName(user: User): string {
return `${user.firstName} ${user.lastName}`;
}
export const t = PropTypes.shape({
firstName: PropTypes.string;
lastName: PropTypes.string;
email: PropTypes.string;
});
export function fullName(user) {
return `${user.firstName} ${user.lastName}`;
}
export interface t {
firstName: string;
lastName: string;
email: string;
}
export function fullName(user: t): string {
return `${user.firstName} ${user.lastName}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment