{"id":18653440,"url":"https://github.com/fullstackacademy/pledge.ashi","last_synced_at":"2025-11-05T16:30:24.344Z","repository":{"id":76926473,"uuid":"85213867","full_name":"FullstackAcademy/pledge.ashi","owner":"FullstackAcademy","description":null,"archived":false,"fork":false,"pushed_at":"2017-06-21T03:36:42.000Z","size":9070,"stargazers_count":1,"open_issues_count":0,"forks_count":3,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-12-27T14:09:40.277Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FullstackAcademy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-16T15:49:09.000Z","updated_at":"2017-06-22T19:21:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"b13012b0-8c16-4d4e-a2a2-e1f490aa65c4","html_url":"https://github.com/FullstackAcademy/pledge.ashi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FullstackAcademy%2Fpledge.ashi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FullstackAcademy%2Fpledge.ashi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FullstackAcademy%2Fpledge.ashi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FullstackAcademy%2Fpledge.ashi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FullstackAcademy","download_url":"https://codeload.github.com/FullstackAcademy/pledge.ashi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239466901,"owners_count":19643597,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T07:11:48.147Z","updated_at":"2025-11-05T16:30:24.296Z","avatar_url":"https://github.com/FullstackAcademy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pledge.js\n\n### Make a promise: build an ES6-style implementation\n\n**Javascript promises** are versatile tools for managing asynchronous results. They are portable and can attach handler functions to an eventual value, in multiple places. Compared to the dead end of standard async callbacks, they restore normal control flow — letting you chain results, `return` new values, and `catch` errors where most convenient.\n\nOne way to understand a thing is to build it yourself. This repo contains a [Jasmine 2.0](http://jasmine.github.io/2.0/introduction.html) test spec (split into thematic chapters). Following the spec in order, we will build a constructor-style promise library similar to [native ECMAScript Promises](https://mzl.la/1jLTOHB), which we will call `pledge.js`. Our promises will be named `$Promise` to avoid triggering browser code. To focus on concepts, `pledge.js` will use public variables and not be standards-compliant (see below).\n\n## Instructions\n\nYou'll need [Node.js](http://nodejs.org) and its package manager `npm` installed.\n\n```sh\nnpm install # automatically builds the docs and opens them\nnpm test\n```\n\nYou will see all the upcoming tests as \"pending\" (yellow). Start writing your own code in the `pledge.js` file. When you pass a test (green), change the next pending test from `xit` to `it` and save. This spec is iterative and opinionated; it is recommended that you do the tests in order and not `xit` out any previous specs. For debugging, you can \"focus\" Jasmine specs/suites with `fit`/`fdescribe`.\n\n## Associated learning materials\n\nThe repo contains the lecture slides and a `.then` flowchart, both in PDF format.\n\n## The state of the art\n\nThere were once multiple proposed [CommonJS promise standards](http://wiki.commonjs.org/wiki/Promises), but one leading standard [Promises/A+](https://www.promisejs.org) and now a compliant [ES6 implementation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) won out. However, many developers use [Bluebird](https://github.com/petkaantonov/bluebird) for its faster-than-native optimizations and many clever features.\n\nHistorically, there have been two ways to generate new promises: CommonJS-style deferreds, and simplified ES6-style constructors. We will study the ES6 style, which has emerged as both the official and de facto standard.\n\n### Warning\n\nLegacy jQuery codebases beware! While jQuery 2 has a version of promises through `$.Deferred`, that implementation differed from current standards and is considered flawed. See [Kris Kowal’s guide.](https://github.com/kriskowal/q/wiki/Coming-from-jQuery) However, modern jQuery users rejoice! jQuery 3 now features P/A+ compliant promises.\n\n## Technical note on non-compliance\n\nOur `pledge.js` library is intended to be a learning exercise. Some of the [Promises/A+](https://promisesaplus.com) standards and general [OOP](http://en.wikipedia.org/wiki/Object-oriented_programming) principles that `pledge.js` will not cover include:\n\n* Handler functions should always be called in an async wrapper (e.g. `setTimeout`). This makes their behavior more deterministic as they execute after a following synchronous code line.\n* The `.then()` function should handle assimilation of promises from other libraries (\"thenables\"). That makes promises interoperable.\n* A promise's state and value should not be directly editable (public), only influenced or accessed through the resolver functions and `.then()`.\n* For simplicity's sake, `pledge.js` does not always follow strict standards terminology. For example, it considers a pledge's `value` as meaning either its fulfillment `data` or rejection `reason`.\n\nThese and other technical details are important, but for someone just beginning to learn they distract from the core behavior and use patterns.\n\n## External Resources for Further Reading\n\n### Canon\n\n* [MDN: ES6 Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) (native functions)\n* [The Promises/A+ Standard](https://www.promisejs.org) (with use patterns and an example implementation)\n\n### General\n\n* [You Don't Know JS: Async and Performance](https://github.com/getify/You-Dont-Know-JS/blob/master/async%20%26%20performance/README.md)\n* [HTML5 Rocks: Promises](http://www.html5rocks.com/en/tutorials/es6/promises/) (deep walkthrough with use patterns)\n* [Nolan Lawson: We Have a Problem with Promises](http://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html)\n* [DailyJS: Javascript Promises in Wicked Detail](http://dailyjs.com/2014/02/20/promises-in-detail/) (build an ES6-style implementation)\n* [Promise Nuggets](http://spion.github.io/promise-nuggets/) (use patterns)\n* [Promise Anti-Patterns](http://taoofcode.net/promise-anti-patterns/)\n\n### Libraries\n\n* [Bluebird](http://bluebirdjs.com) (the current favorite for speed \u0026 features among many JS developers)\n* [Kris Kowal \u0026 Domenic Denicola: Q](https://github.com/kriskowal/q) (the library Angular's $q mimics; great examples \u0026 resources)\n\n### Angular and Related\n\n* [AngularJS documentation for $q](https://docs.angularjs.org/api/ng/service/$q)\n* [AngularJS Corner: Using promises and $q to handle asynchronous calls](http://chariotsolutions.com/blog/post/angularjs-corner-using-promises-q-handle-asynchronous-calls/)\n* [Xebia: Promises and Design Patterns in AngularJS](http://blog.xebia.com/2014/02/23/promises-and-design-patterns-in-angularjs/)\n* [AngularJS / UI Router / Resolve](http://www.jvandemo.com/how-to-resolve-angularjs-resources-with-ui-router/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffullstackacademy%2Fpledge.ashi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffullstackacademy%2Fpledge.ashi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffullstackacademy%2Fpledge.ashi/lists"}