Skip to content
/ promesse Public

A functional style Promises/A+ implementation that aims to be concise and clean.

Notifications You must be signed in to change notification settings

djfm/promesse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Promesse

Build Status

Promises/A+ logo

Promesse is a Promises/A+ compliant Promise library. This implementation passes all the tests of the standard test suite.

Why oh Why?

I've written it because I love using promises in JS and I like to know how the tools I use work.

There are many implementations out there, I wanted mine to be very small and written as much as possible in functional programming style.

I'm rather happy about the result:

  • 98 lines of code (no comments, comments are for the weak), so probably one of the shortest implementations out there
  • looks a bit like Haskell :)

It's been a really enriching experience, now I know a lot more about the subtleties of promises than any documentation would tell.

Besides, working against an existing huge test suite is a cool programming exercise.

Obviously this is a toy project, but I'd be interested in having feedback on:

  • does the code make sense to you? or did I just write some "write-only" software?
  • can you see ways to make it smaller without making it too obscure / unreadable?
  • can you see other functional patterns that I could use to make the code more concise?

Installing

This is probably not very useful since promises are standard, but, if for some reason you need to:

npm i --save aplus-promesse

Testing

git clone https://github.com/djfm/promesse
cd promesse
npm i
npm test

There are two test suites, the one from Promises/A+, and the one I wrote to help me when I did not understand the feedback from the official tests.

Making it Smaller

Now that the library is working and tested, I want to make it smaller in terms of number of lines of code.

The rules are:

  • lines must not exceed 80 columns
  • block declarations (by that I mean a declaration that takes more than one line or a succession of one line declarations) and top level declarations are followed with one blank line at least
  • more subjectively: the code needs to remain easy to read

About

A functional style Promises/A+ implementation that aims to be concise and clean.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published