Giter Club home page Giter Club logo

psymon's Introduction

psymon

psymon says this is deprecated.

Class based React components are often misused. They can grow to become thousands of lines of code which costs people time and businesses money. Furthermore; stateful components are rarely tested correctly.

psymon aims to make it simple to piece stateful components together in a fucntional way that allows maximum modularity and testability. Essentially, whereas React componentizes the UI, psymon componentizes your UI logic.

API

Relevant Types

type ObjectOfAnyT = {
	[name: string]: any
};

type ObjectOfFunctionsT = {
	[name: string]: Function
};

type SetupT = {
	state: ObjectOfAnyT,
	methods: ObjectOfFunctionsT,
	lifecycle: ObjectOfFunctionsT,
	component: React.ComponentType
};

psymon.component(name: string, setup: SetupT, pure: boolean)

Takes a stateless component, methods, lifecycle hooks, and state, and generates a stateful component. Includes pure option that is utilized by psymon.pureComponent, but can be an alternative way of creating or toggling purity.

psymon.pureComponent(name: string, setup: SetupT)

Takes a stateless component, methods, lifecycle hooks, and state, and generates a stateful pure component.


Usage Example

// index.js

import psymon from 'psymon';

import { component } from './component';
import * as lifecycle from './lifecycle';
import * as methods from './methods';

const state = {
	inputValue: '',
	todos: []
};

export const TodoList = psymon.component('TodoList', {
	component,
	lifecycle,
	methods,
	state
});
// ./lifecycle.js

export const componentDidUpdate = (self) => () => {
	// Whatever you want to do after update.
	// Use the `self` reference provided, not `this`.
};
// ./methods.js

export const setInputValue = (self) => (event) => {
	self.setState({
		inputValue: event.currentTarget.value
	});
};

export const addTodo = (self) => () => {
	self.setState({
		todos: [...self.state.todos, self.state.inputValue],
		inputValue: ''
	});
};

export const removeTodo = (self) => (index) => {
	self.setState({
		todos: self.state.todos.filter((todo, i) => i !== index)
	});
};

TODO

  • Testing. (Created on CodeSandbox as a simple experiment.)

psymon's People

Contributors

colshacol avatar

Stargazers

 avatar Rafael Klaessen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.