Meta Application Function
2012 Minori Yamashita ympbyc@gmail.com
Pasta is a function that helps you write JavaScript MVC applications functionally.
Underscore, Underscore-fix
Pasta takes all it needs to setup an application for you and returns a function called signal
.
Pasta(Model, UI, View, initialData); //=> signal
Pasta()
produces a function named signal
. signal()
produces a function that will call a function in your model.
$("button").click(pasta.signal("some_function_name", function (ev) {
return "data";
}));
Pasta's state management model is heavily influenced by that of Clojure's. There is no data mutated throughout the execution.
Pasta is a great tool to avoid pieces of uncontrolled states scattered all over your app. If your app is made up of hundreds of mutable objects, it is rather cumbersome to gather them all and inspect or save the state of the app while it is running. Meanwhile, Pasta forces every changeable data to be put into one big hashmap, allowing us to inspect, save, load, metaprogram the app.
Pasta does not assume a particular platform where it is used. You can use Pasta in any JavaScript environment with any GUI APIs.
This is very important. Pasta does not mix data and behaviours. models and views are collections only of functions,
and the state is a collection only of data. With Pasta, it is highly possible to create apps that do not contain a single this
keyword.
You could of course use your favourite data structure to put into the state or use OO libraries for UI manipulations, but it is not the concern of Pasta.
The state of a Pasta app can be persisted into localstorage, remote server or anywhere you can think of. Just serialize it into JSON and save.
Here goes a crazy tip: you can save the state into the state itself! If you know what I mean...
var Model = _.module(
{},
function save_history (state) {
return {previousState: state};
},
function back_to_the_future (state) {
//go back 2 steps
return state.previousState.previousState;
}
);
Pasta is licensed under MIT licence
Pasta() now returns the signal function instead of an object.