Skip to content
Create a gist now

Instantly share code, notes, and snippets.

@wycats /ligament.js secret
Created Sep 16, 2011

/**
* Copyright (C) 2011 by Yehuda Katz
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
**/
// ligament.js is the smallest, lightest-weight JavaScript MVC framework.
//
// ligament.js requires modern browsers, which provide Object.create.
// Newer browsers are the future, older browsers are the past.
//
// If you really must support older browsers like IE8, you can use the
// hot polyfill for Object.create found at
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/create
// Usage:
// MyModel = Object.create(M);
// instance = Object.create(MyModel);
// instance.firstName = "Brendan";
// instance.lastName = "Eich";
//
// Because ligament.js uses *real* prototype inheritance, like Spine, you can add new
// methods to the MVC layers by simply extending MVC objects:
// M.toString = function() { console.log("All models get this method!"); };
// Person = Object.create(M);
// Person.fullName = function() { return this.firstName + ' ' + this.lastName; }
// jeremy = Object.create(Person);
// jeremy.firstName = "Jeremy";
// jeremy.lastName = "Ashkenas";
// jeremy.fullName() //=> Jeremy Ashkenas
//
// That's it! Why deal with all the bloat of JavaScript frameworks. Use ligament.js!
M = {}, V = {}, C = {};
@jedisct1

Awesome :)

@akahn
akahn commented Sep 16, 2011

I think I'll stick with David Mark's kidneystones.js

@kurko
kurko commented Sep 16, 2011

Genius :)

@ryan-blunden

What's the size of this framework minified?

@honza
honza commented Sep 16, 2011

Does it support vapor.js?

@sudarshanbhat

I get jslint errors, you should throw in this comment line

/*globals M V C*/

@rgrove
rgrove commented Sep 16, 2011

Is there a jQuery plugin for this?

@sneakyness

This isn't running for me in Netscape Navigator 3.0

@erikvorhes

Mosaic support, please.

@markburns

Does this work on lynx?

@jblotus
jblotus commented Sep 16, 2011

did you provide tests?

@kikito
kikito commented Sep 16, 2011

Bah, it doesn't have tests...

@jblotus
jblotus commented Sep 16, 2011

also, can we get this as a module for Node?

@casperbp

@romanvbabenko: Your fork is the opposite of MVC. JavaScript is call-by-sharing for objects. You've created a framework for the GOD object.

@lunich
lunich commented Sep 16, 2011

@romanvbabenko: data sharing between M, V and C never was easier!

@jm3
jm3 commented Sep 16, 2011

will this work with Rails 4?

@tj
tj commented Sep 16, 2011

perfect! love it.

@bloudermilk

Someone on Twitter said this framework wasn't scalable. My web 3.0 app needs to be scalable.

@tj
tj commented Sep 16, 2011

it needs to be coffeescript, cant write js without coffeescript come on now

@neeleshs

This is not enterprise quality. There is no XML configuration for this framework!

@crgwbr
crgwbr commented Sep 16, 2011

Fyi: This framework only works properly when the user is connected to the server via a Denon Dedicated Link Cable

@robyurkowski

I don't have javascript enabled because my grandma said I could get viruses that way. Can I still run this on my geocities page?

@atomantic

Every language should have this library!

@jblotus
jblotus commented Sep 16, 2011

i guess you could do this with ruby too

@lksmth
lksmth commented Sep 16, 2011

does this support canvas?

@jblotus
jblotus commented Sep 16, 2011

i'm also pretty sure the is patented somewhere. hope you got lawyerz

@omenking

hilarious

@rmoriz
rmoriz commented Sep 17, 2011

why no nosql support?
why no node support?

that's never ever going to be web-scale!

@ghost
Unknown commented Sep 17, 2011

Did anyone consider alternatives to MVC? This is not 1990's.

@spacez320

Towards comment asking for browser support; read beneath the copyright.

@mdesantis
                                                              CAPTAIN, I CAN SEE
                                                        THE M = {}, V = {}, C = {}; LAND!
                                                 _____|\ .                
                                            _.--| LOL |:  \O.===o                
                                           <____|.----||  ||`                 
                                                  .---''--;;                
                                 The               ;..__..'    _...         
                                  Lulz           ,'/  ;|/..--''    \        
                                   Boat        ,'_/.-/':            :       
                                          _..-'''/  /  |  \    \   _|/|     
                                         \      /-./_ \;   \    \,;'   \    
                                         ,\    / \:  `:\    \   //    `:`.  
                                       ,'  \  /-._;   | :    : ::    ,.   . 
                                     ,'     ::   /`-._| |    | || ' :  `.`.)
                                  _,'       |;._:: |  | |    | `|   :    `' 
                                ,'   `.     /   |`-:_ ; |    |  |  : \      
                                `--.   )   /|-._:    :          |   \ \     
                                   /  /   :_|   ;`-._;   __..--';    : :    
                                  /  (    ;|;-./_  _/.-:'o |   /     ' |    
                                 /  , \._/_/_./--''/_|:|___|_,'        |    
                                :  /   `'-'--'----'---------'          |    
                                | :     O ._O   O_. O ._O   O_.      ; ;    
                                : `.      //    //    //    //     ,' /     
                              ~~~`.______//____//____//____//_______,'~     
                                        //    //~   //    //                
                                 ~~   _//   _//   _// ~ _//     ~           
                               ~     / /   / /   / /   / /  ~      ~~       
                                    ~~~   ~~~   ~~~   ~~~                   
@bengillies

The view and controller objects look pretty complicated to me. Could we get some examples on how to use them please?

@ghost
Unknown commented Sep 17, 2011
@josscrowcroft

No documentation / example apps!? I'd never be able to get this past my CTO.

@contra
contra commented Sep 17, 2011

Where are your tests? Why is this not written in coffeescript? BDD? DDD? TDD? Documentation? This needs a lot of work.

@MattiSG
MattiSG commented Sep 17, 2011

Nice, but I'm waiting for a micro-framework version of it.

@n1k0
n1k0 commented Sep 17, 2011

mandatory fork implementing MTV rather than MVC is here https://gist.github.com/11f67cc9851a12190d5c

@DAddYE
DAddYE commented Sep 17, 2011

Hhahaha

@eliaskg
eliaskg commented Sep 17, 2011

It's definitely not ready for production.

@sebslomski

Is it web-scale?

@MattiSG
MattiSG commented Sep 17, 2011

Microsoft said it is not the native HTML5 experience.

@postmodern

Can someone port this to CoffeeScript?

@mark-ellul

Can someone write a Jquery plugin for this please? ;)

@pedromtavares

can you please write a wiki this is bad documentation tnx

@jeffreyiacono

Can you provide the link to the Todo app that demonstrates Ligament.js usage? ;)

@likethesky

I hear sinew.js is much more modern and cleaner than ligament, which is so, like "early September 2011"...

@NKjoep
NKjoep commented Sep 18, 2011

and what about A/B testing? I need a framework for it...

@derickbailey

don't forget about the coffeescript version! after all, no javascript mvc framework would be complete without it!

M = new (M = function(){
  this.M = function(){};
})()();

V = new (V = function(){
  this.V = function(){};
})()();

C = new (C = function(){
  this.C = function(){};
})()();

no... sorry... that's the version that coffeescript generated.

@mdesantis

and this is the minified version... for who cares about performance

@n1k0
n1k0 commented Sep 18, 2011

okay but is it enterprise-ready?

@eliperelman

For those that use MVVM and not MVC: https://gist.github.com/34d3bd7be864cced6188
:D

@lmcd
lmcd commented Sep 30, 2011

Doesn't work in VB6

@amoln
amoln commented Sep 30, 2011

The fwk needs 'Connect with Facebook/Twitter/LinkedIn' integration.

@giulianoliker

My head just explo*BOOOOM*

@cayasso
cayasso commented Sep 30, 2011

For those of you asking for testing this beast... wait no more:

console.log((M !== V && V !== C && C !== M) ? 'OK' : 'Not OK');
Who say it is not tested ah ah?
BTW. The test is only supported on modern browsers so no complains please!

@oroce
oroce commented Oct 2, 2011

is there any 'in the wild' example?

@rassar
rassar commented Oct 5, 2011

this makes no sense. no sense at all! How the hell is this any different from just plain procedural js?

@MattiSG
MattiSG commented Oct 5, 2011

@rassar you clearly don't understand the MVC architecture. 🔥

@rassar
rassar commented Oct 6, 2011

@MattiSG great, I dont understand. Care you to restate something else that's as obvious as this?
that's WHY I asked the question!!!! Either answer it, or remain silent

@MattiSG
MattiSG commented Oct 6, 2011

@rassar Damn, man…

This gist is actually a joke. It makes fun of all the JS frameworks that all sell "MVC" as their main argument and motto, while MVC is an architecture, therefore not dependent on an implementation but rather on the respect of a simple concept: separate your models, views and controllers. Which something as simple as three different JS objects achieves, if used properly by the programmer.
You might have noticed that many comments ask for things even dumber: minified versions, plugins for X (X being whatever framework)… they all make fun of the newly found (~9 months - 1 year) JS frenzy where every framework / to-js-compiled-language has its zealots and it seemed necessary that JS code, to be credible, had a CoffeeScript version, a jQuery version, etc etc.

You may find the documentation at http://en.wikipedia.org/wiki/Sarcasm interesting to understand it better, if necessary. More generally, you might be interested in http://en.wikipedia.org/wiki/Humor. I actually thought you were into it too, as your comment could be understood as ironic (see http://en.wikipedia.org/wiki/Irony, might help).

In the same vein, see also: https://github.com/madrobby/vapor.js .

Is that clear enough an answer for you? :(

@lmcd
lmcd commented Oct 6, 2011

Ignore this @MattiSG troll. ligament.js is a great way of embracing the MVC paradigm in JavaScript.

@rassar
rassar commented Oct 6, 2011

haha, awesome. I love the way you tought me a little of grammar and worldview...

So I am dumb, big deal. But I did build a app based on this M V C thing, and it worked! hahahahaha

@mdesantis

@rassar if you wrote an app based on ligament.js, please share it; ligament.js misses an example app.

@n1k0
n1k0 commented Oct 6, 2011

UNSUBSCRIBE

@kurko
kurko commented Oct 6, 2011

UNSUBSCRIBE +1

@likethesky

@lmcd right on! That @MattiSG is a total troll. I'm so glad I have Ligament.js on my resume. Everyone, please tell ALL recruiters to add Ligament to their keyword searches, if they want to get the hottest JS coders. @rassar please see http://theotherpages.org/quote-14.html for more examples of DWS ( http://acronyms.thefreedictionary.com/Dripping+with+Sarcasm ). @n1k0 @kurko please see https://github.com/account/notifications ("Comments after me on gists") @everyone else: Yeah, the long and the short of it is: we're all bored to tears, couldn't care less, we all know there's one born every minute, so I'm going to put my foot down, take one for the team, you know who you are: you can run but you can't hide, so ideally my post here is the kiss of death for this thread! (@rassar see http://suspense.net/whitefish/cliche.htm ) :-D

@josscrowcroft
@haochong

cool

@juanpastas

Which one should I use? this or ember?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.