Top Related Projects
Application Architecture for Building User Interfaces
A simple library for uni-directional dataflow application architecture with React extensions inspired by Flux
Isomorphic flux implementation
A JS library for predictable global state management
:hammer_and_wrench: Flux architecture tools for React
Quick Overview
Marty.js is a JavaScript library for building isomorphic web applications using React and Flux architecture. It provides a set of tools and utilities to simplify state management, data fetching, and routing in both client-side and server-side rendering scenarios.
Pros
- Simplifies the implementation of Flux architecture in React applications
- Supports isomorphic/universal JavaScript applications
- Provides a consistent API for both client-side and server-side rendering
- Includes built-in support for data fetching and caching
Cons
- No longer actively maintained (last commit was in 2016)
- Limited community support and ecosystem compared to more modern state management solutions
- May have compatibility issues with newer versions of React and related libraries
- Learning curve for developers unfamiliar with Flux architecture
Code Examples
- Creating a Marty.js Store:
const UserStore = Marty.createStore({
id: 'UserStore',
getInitialState: () => ({
users: {}
}),
handlers: {
addUser: 'USER_ADDED'
},
addUser(user) {
this.state.users[user.id] = user;
this.hasChanged();
}
});
- Defining a Marty.js Action:
const UserActions = Marty.createActionCreators({
addUser(user) {
this.dispatch('USER_ADDED', user);
}
});
- Using Marty.js with React components:
const UserList = React.createClass({
mixins: [Marty.createStateMixin(UserStore)],
getState() {
return {
users: UserStore.getUsers()
};
},
render() {
return (
<ul>
{Object.values(this.state.users).map(user => (
<li key={user.id}>{user.name}</li>
))}
</ul>
);
}
});
Getting Started
To get started with Marty.js, follow these steps:
-
Install Marty.js via npm:
npm install marty
-
Include Marty.js in your project:
import Marty from 'marty';
-
Create stores, actions, and components using Marty.js APIs as shown in the code examples above.
-
Set up the Marty.js application:
const app = new Marty.Application(); app.register('userStore', UserStore); app.register('userActions', UserActions);
-
Render your React components with Marty.js:
Marty.renderToDOM(app, UserList, document.getElementById('app'));
Note: As Marty.js is no longer actively maintained, consider using more modern state management solutions for new projects.
Competitor Comparisons
Application Architecture for Building User Interfaces
Pros of Flux
- Official implementation by Facebook, ensuring alignment with React ecosystem
- Simpler architecture with unidirectional data flow
- Extensive documentation and community support
Cons of Flux
- Less opinionated, requiring more boilerplate code
- Lacks built-in features like isomorphic support and API integration
- Can be challenging for beginners due to its flexibility
Code Comparison
Flux:
var AppDispatcher = require('./AppDispatcher');
var TodoConstants = require('./TodoConstants');
var TodoActions = {
create: function(text) {
AppDispatcher.dispatch({
actionType: TodoConstants.TODO_CREATE,
text: text
});
}
};
Marty:
var TodoActions = Marty.createActionCreators({
addTodo: function (text) {
this.dispatch(TodoConstants.ADD_TODO, text);
}
});
Key Differences
- Marty provides a more opinionated structure, reducing boilerplate
- Flux offers more flexibility but requires more setup
- Marty includes built-in features like isomorphic rendering and API integration
- Flux has a larger community and more extensive documentation
- Marty's syntax is more concise, while Flux is more verbose but explicit
Both libraries aim to implement the Flux architecture, but Marty offers a more batteries-included approach, while Flux provides a foundation for custom implementations.
A simple library for uni-directional dataflow application architecture with React extensions inspired by Flux
Pros of Refluxjs
- Simpler and more lightweight architecture compared to Marty
- Easier to learn and implement for developers new to Flux-like patterns
- More flexible and less opinionated, allowing for easier customization
Cons of Refluxjs
- Less structured approach may lead to inconsistencies in larger applications
- Lacks built-in support for isomorphic/universal JavaScript applications
- Limited tooling and debugging capabilities compared to Marty's ecosystem
Code Comparison
Refluxjs:
var Actions = Reflux.createActions([
"increment",
"decrement"
]);
var CounterStore = Reflux.createStore({
listenables: Actions,
onIncrement: function() { this.trigger(this.count++); },
onDecrement: function() { this.trigger(this.count--); }
});
Marty:
var CounterActions = Marty.createActionCreators({
increment: function() { this.dispatch('INCREMENT'); },
decrement: function() { this.dispatch('DECREMENT'); }
});
var CounterStore = Marty.createStore({
handlers: {
'INCREMENT': 'increment',
'DECREMENT': 'decrement'
},
increment: function() { this.setState({ count: this.state.count + 1 }); },
decrement: function() { this.setState({ count: this.state.count - 1 }); }
});
Both libraries aim to implement Flux-like architectures, but Refluxjs offers a more streamlined approach with less boilerplate. Marty provides a more structured and opinionated framework, which can be beneficial for larger applications or teams requiring stricter conventions.
Isomorphic flux implementation
Pros of Alt
- Simpler API with less boilerplate code
- Better documentation and examples
- More active community and frequent updates
Cons of Alt
- Less flexibility in handling complex state management scenarios
- Limited built-in support for isomorphic/universal applications
- Steeper learning curve for developers new to Flux architecture
Code Comparison
Alt:
class LocationActions {
updateLocation(location) {
return location;
}
}
class LocationStore {
constructor() {
this.location = null;
this.bindListeners({
handleUpdateLocation: LocationActions.UPDATE_LOCATION
});
}
handleUpdateLocation(location) {
this.location = location;
}
}
Marty:
const LocationConstants = Marty.createConstants([
'UPDATE_LOCATION'
]);
const LocationActions = Marty.createActionCreators({
updateLocation(location) {
this.dispatch(LocationConstants.UPDATE_LOCATION, location);
}
});
const LocationStore = Marty.createStore({
handlers: {
[LocationConstants.UPDATE_LOCATION]: 'handleUpdateLocation'
},
getInitialState() {
return { location: null };
},
handleUpdateLocation(location) {
this.state.location = location;
this.hasChanged();
}
});
Both Alt and Marty are Flux implementations for React applications. Alt offers a more straightforward API with less boilerplate, making it easier for beginners to grasp. However, Marty provides more flexibility for complex state management scenarios and better support for isomorphic applications. The code comparison shows that Alt requires less setup code, while Marty offers a more structured approach with separate constants and action creators.
A JS library for predictable global state management
Pros of Redux
- More active development and larger community support
- Better integration with React ecosystem and tooling
- Simpler API and learning curve for beginners
Cons of Redux
- More boilerplate code required for setup and actions
- Can be overkill for smaller applications
- Requires careful management of immutability
Code Comparison
Redux:
const reducer = (state = initialState, action) => {
switch (action.type) {
case 'INCREMENT':
return { ...state, count: state.count + 1 };
default:
return state;
}
};
Marty:
class CounterStore extends Marty.Store {
constructor(options) {
super(options);
this.state = { count: 0 };
this.handlers = {
increment: 'handleIncrement'
};
}
handleIncrement() {
this.setState({ count: this.state.count + 1 });
}
}
Redux focuses on a single reducer function and pure state updates, while Marty uses a class-based approach with built-in state management. Redux's approach is more flexible but requires more setup, whereas Marty provides a more structured but opinionated solution.
:hammer_and_wrench: Flux architecture tools for React
Pros of Fluxxor
- Simpler API with less boilerplate code
- Better documentation and examples
- More mature and stable project with longer history
Cons of Fluxxor
- Less active development and community support
- Fewer features and integrations compared to Marty
- Limited TypeScript support
Code Comparison
Fluxxor:
var actions = {
addTodo: function(text) {
this.dispatch('ADD_TODO', {text: text});
}
};
var TodoStore = Fluxxor.createStore({
initialize: function() {
this.todos = [];
this.bindActions(
'ADD_TODO', this.onAddTodo
);
},
onAddTodo: function(payload) {
this.todos.push({text: payload.text});
this.emit('change');
}
});
Marty:
class TodoActions extends Marty.ActionCreators {
addTodo(text) {
this.dispatch(TodoConstants.ADD_TODO, text);
}
}
class TodoStore extends Marty.Store {
constructor(options) {
super(options);
this.state = [];
this.handlers = {
addTodo: TodoConstants.ADD_TODO
};
}
addTodo(text) {
this.state.push({text: text});
this.hasChanged();
}
}
Both libraries implement the Flux architecture, but Fluxxor has a more straightforward approach with less boilerplate. Marty offers more structure and features, which can be beneficial for larger applications but may introduce complexity for simpler projects.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Marty is no longer actively maintained. Use Alt or Redux instead. More info.
Marty is a Javascript library for state management in React applications. It is an implementation of the Flux architecture.
Quick start
make build # rebuild source
make docs # show documentation on http://localhost:4000
Releasing
make release # inc's patch, builds, creates tag, pushes to github and then publishes to npm
make release inc={inc} # specify what to version part to increment (major, premajor, minor, preminor, patch, prepatch, prerelease)
make release-docs #Â builds documentation and copies into ../marty-gh-pages
TypeScript
A TypeScript definition is available at marty.d.ts
. Please note that it requires the React definition from DefinitelyTyped.
Git Commit Messages
- Use the present tense ("Add feature" not "Added feature")
- Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
- Limit the first line to 72 characters or less
- Reference issues and pull requests liberally
- Consider starting the commit message with an applicable emoji:
- :lipstick:
:lipstick:
when improving the format/structure of the code - :racehorse:
:racehorse:
when improving performance - :non-potable_water:
:non-potable_water:
when plugging memory leaks - :memo:
:memo:
when writing docs - :penguin:
:penguin:
when fixing something on Linux - :apple:
:apple:
when fixing something on Mac OS - :checkered_flag:
:checkered_flag:
when fixing something on Windows - :bug:
:bug:
when fixing a bug - :fire:
:fire:
when removing code or files - :green_heart:
:green_heart:
when fixing the CI build - :white_check_mark:
:white_check_mark:
when adding tests - :lock:
:lock:
when dealing with security - :arrow_up:
:arrow_up:
when upgrading dependencies - :arrow_down:
:arrow_down:
when downgrading dependencies
- :lipstick:
(From atom)
Maintainers
##Â License
Top Related Projects
Application Architecture for Building User Interfaces
A simple library for uni-directional dataflow application architecture with React extensions inspired by Flux
Isomorphic flux implementation
A JS library for predictable global state management
:hammer_and_wrench: Flux architecture tools for React
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot