• Stars
    star
    183
  • Rank 210,154 (Top 5 %)
  • Language
    CoffeeScript
  • License
    MIT License
  • Created about 13 years ago
  • Updated almost 12 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Coffeescript/Javascript method combinations for Underscore projects

You Are 'Da Chef

What is it?

This library adds before, after, around, and guard method combinations to underscore.js projects, in much the same style as the Common Lisp Object System or Ruby on Rails controllers. With method combinations, you can easily separate concerns.

For example:

class Wumpus
    roar: ->
        # ...
    run: ->
        #...

class Hunter
    draw: (bow) ->
        # ...
    quiver: ->
        # ...
    run: ->
        #...

hydrate = (object) ->
    # code that hydrates the object from storage

YouAreDaChef(Wumpus, Hunter)

    .before 'roar', 'draw', 'run', ->
        hydrate(this)
        
    .after 'roar', 'draw', ->
        @trigger 'action'

There must be more to it than that

Yes there is, there's a Quick Start Guide and a discussion of the special sauce, YouAreDaChef's inheritance model.

Is it any good?

Yes.

I don't believe you!

C'mon, meta-programmed code is read-only. It looks good, but when it comes time to debug or modify anything, it's a nightmare to step through it in the debugger and figure out what's going on.

That's often the case, but starting with version 1.0, YouAreDaChef is designed to make code that's easy to write, not just easy to read. Instead of blindly patching methods with wrapper functions, YouAreDaChef stores all of the "advice" functions in a special data structure in the class. You can inspect each class separately. You can provide names for the advice you add to methods, which makes it easier to keep track of the advice you have provided. Since you have the advice and can inspect it, you can write unit tests for your advice and debug the advice you have provided more easily. The .inspect function does add some code complexity to the YouAreDaChef library, but it makes writing and debugging code written with the YouAreDaChef library much easier.

Can I use it with pure Javascript?

Yes.

Can I install it with npm?

Yes:

npm install YouAreDaChef

Will it make me smarter?

No, but it can make you appear smarter. Just explain that guard advice is a monad:

YouAreDaChef(EnterpriseyLegume)

  .when /write(.*)/, ->
    @user.hasPermission('write', match[1])

Guard advice works like a before combination, with the bonus that if it returns something falsely, the pointcut will not be executed. This behaviour is similar to the way ActiveRecord callbacks work.

You can also try making a cryptic reference to a computed, non-local COMEFROM.

I might not need all of its awesomeness

Have a look at method-combinators.

Where can I read more?

Quick Start Guide
Separating Concerns in CoffeeScript using Aspect-Oriented Programming
Implementing Garbage Collection in CS/JS with Aspect-Oriented Programming

In memoriam

YouAreDaChef's method advice is loosely based on Lisp Flavors, specifically the inheritance of before and after advice plus the overriding of default advice (called daemon in Flavors). Dan Weinreb (d. 2012) played an important role in the development of Lisp. He is missed by many.

post scriptum

I'm writing a book called CoffeeScript Ristretto. Check it out!

Et cetera

YouAreDaChef was created by Reg "raganwald" Braithwaite. It is available under the terms of the MIT License.

More Repositories

1

javascript-allonge

Markdown source for the book "JavaScript Allongé"
JavaScript
758
star
2

presentations

Conference Talks and Proposals
751
star
3

allong.es

JavaScript
486
star
4

andand

The Maybe Monad in idiomatic Ruby
Ruby
302
star
5

JQuery-Combinators

The jQuery plugin with the academic name and the pragmatic methods
JavaScript
213
star
6

Katy

CoffeeScript and JavaScript Combinators
CoffeeScript
172
star
7

method-combinators

CoffeeScript
120
star
8

javascript-allonge-six

https://leanpub.com/javascriptallongesix
JavaScript
104
star
9

hashlife

JavaScript
58
star
10

oscin.es

n. pl. 1. (Zool.) Singing birds; a group of the Passeres, having numerous syringeal muscles, conferring musical ability
JavaScript
55
star
11

javascript-spessore

Manuscript for JavaScript Spessore
JavaScript
49
star
12

Underscore-Matchers-for-Jasmine

CoffeeScript
39
star
13

raganwald.github.com

raganwald.com jekyll source
HTML
31
star
14

cafeaulife

Gosper’s HashLife in CoffeeScript
CoffeeScript
30
star
15

wood_and_stones

Use your iPad as a Goban
JavaScript
29
star
16

combinators.info

JavaScript
23
star
17

jQuery-Predicates

.exists() and does_not_exist() for jQuery
JavaScript
16
star
18

ristrettolo.gy

jekyll source for http://ristrettolo.gy
JavaScript
10
star
19

FRACTRAN

Code to accompany “ Remembering John Conway's FRACTRAN, a ridiculous, yet surprisingly deep language”
JavaScript
10
star
20

supervis.es

CoffeeScript
9
star
21

string-lambdas

String lambdas for JavaScript and CoffeeScript
CoffeeScript
8
star
22

braythwayt.com

Reg Braithwaite's old weblog plus the odd non-technical blow hardiness
HTML
7
star
23

the-little-elixir-book

Fun with "The Little Elixir and OTP Guidebook"
Elixir
6
star
24

presentation_decks

Presentation decks from a few speaking engagements
6
star
25

raganwald.posterous.com

The content from my posterous blog, somewhat
5
star
26

mazerunner

Builds a maze in ES6 using Eller's Algorithm as described by Jamis Buck.
JavaScript
5
star
27

AMA

A lightweight “Ask me anything” repository inspired by @holman and @r00k
5
star
28

still-failing-still-learning-still-optimistic

3
star
29

stata

Read and write support for the Stata binary format
C
2
star
30

MacOSMendel

Java
1
star
31

shunting-yard

The collected shunting-yard code from raganwald.com
JavaScript
1
star
32

shunting-yard-dot-rb

A toy shunting yard implementation in Ruby
Ruby
1
star
33

kato

CoffeeScript-style OO for JavaScript
1
star