secret
Last active

  • Download Gist
ligament.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
/**
* 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 = {};

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

What's the size of this framework minified?

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

/*globals M V C*/

Is there a jQuery plugin for this?

This isn't running for me in Netscape Navigator 3.0

Mosaic support, please.

Does this work on lynx?

did you provide tests?

Bah, it doesn't have tests...

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

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

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

will this work with Rails 4?

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

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

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

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

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?

Every language should have this library!

i guess you could do this with ruby too

does this support canvas?

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

why no nosql support?
why no node support?

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

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

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

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

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

I recommend you don't use them.

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

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

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

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

It's definitely not ready for production.

Microsoft said it is not the native HTML5 experience.

Can someone port this to CoffeeScript?

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

can you please write a wiki this is bad documentation tnx

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

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

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

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.

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

okay but is it enterprise-ready?

Doesn't work in VB6

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

My head just explo****BOOOOM****

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!

is there any 'in the wild' example?

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

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

@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

@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? :(

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

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

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

@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

this is getting a fair bit less entertaining... sorry to call it out.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.