{"id":13807140,"url":"https://github.com/poteto/ember-pipeline","last_synced_at":"2025-05-14T00:30:47.962Z","repository":{"id":57224145,"uuid":"88228858","full_name":"poteto/ember-pipeline","owner":"poteto","description":"Railway oriented programming in Ember","archived":true,"fork":false,"pushed_at":"2018-01-12T01:01:35.000Z","size":102,"stargazers_count":19,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-20T20:49:44.816Z","etag":null,"topics":["ember","ember-addon","experimental","not-production-ready","pipeline","railway-oriented-programming"],"latest_commit_sha":null,"homepage":"http://bit.ly/ember-pipeline-demo","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/poteto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-14T03:22:06.000Z","updated_at":"2024-10-23T09:09:27.000Z","dependencies_parsed_at":"2022-08-30T02:10:43.624Z","dependency_job_id":null,"html_url":"https://github.com/poteto/ember-pipeline","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poteto%2Fember-pipeline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poteto%2Fember-pipeline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poteto%2Fember-pipeline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poteto%2Fember-pipeline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/poteto","download_url":"https://codeload.github.com/poteto/ember-pipeline/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254046215,"owners_count":22005556,"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":["ember","ember-addon","experimental","not-production-ready","pipeline","railway-oriented-programming"],"created_at":"2024-08-04T01:01:21.556Z","updated_at":"2025-05-14T00:30:47.016Z","avatar_url":"https://github.com/poteto.png","language":"JavaScript","funding_links":[],"categories":["Packages"],"sub_categories":["Job queues"],"readme":"# ember-pipeline ![Download count all time](https://img.shields.io/npm/dt/ember-pipeline.svg) [![Build Status](https://travis-ci.org/poteto/ember-pipeline.svg?branch=master)](https://travis-ci.org/poteto/ember-pipeline) [![npm version](https://badge.fury.io/js/ember-pipeline.svg)](https://badge.fury.io/js/ember-pipeline) [![Ember Observer Score](http://emberobserver.com/badges/ember-pipeline.svg)](http://emberobserver.com/addons/ember-pipeline)\n\n[Railway oriented programming](https://fsharpforfunandprofit.com/rop/) in Ember. To install:\n\n```\nember install ember-pipeline\n```\n\n## Philosophy\n\n`ember-pipeline` allows you to compose a pipeline of (promise aware) methods on an object using \"railway oriented programming\". That is, if any of the methods in the pipeline returns a `CANCEL` token, the entire pipeline exits and can be optionally handled by another method. If the host `Ember.Object` is destroyed, the pipeline is aborted as well.\n\nFor example:\n\n```js\nimport Ember from 'ember';\nimport { pipeline, step, CANCEL } from 'ember-pipeline';\n\nconst { computed, get } = Ember;\n\nexport default Component.extend({\n  fetchStoreLocations: computed(function() {\n    return pipeline(this, [\n      step('requestGeolocation'),\n      step('fetchStoresInProximity'),\n      step('sortStoresByDistance'),\n      step('alwaysCancels')\n    ]).onCancel((cancellation) =\u003e this.handleCancel(cancellation));\n  }),\n\n  requestGeolocation() { /* ... */ },\n  fetchStoresInProximity() { /* ... */ },\n  sortStoresByDistance() { /* ... */ },\n\n  alwaysCancels() {\n    return CANCEL();\n  },\n\n  handleCancel(cancellation) {\n    switch (cancellation.fnName) {\n      case 'requestGeolocation':\n        // show error message saying you didn't allow us to use geo api\n        break;\n      case 'fetchStoresInProximity':\n        // no stores around you, sorry!\n        break;\n      case 'sortStoresByDistance':\n        // we used bubble sort\n        break;\n      default:\n        // no cancel handler\n        console.log(`last value: ${cancellation.result}, reason: ${cancellation.reason}`);\n        break;\n    }\n  }),\n\n  actions: {\n    fetchStoreLocations(...args) {\n      return get(this, 'fetchStoreLocations').perform(...args);\n    }\n  }\n});\n```\n\n## Usage\n\nFirst, create a pipeline using `pipeline` and `step`. You can also define a cancel handler:\n\n```js\nreturn pipeline(this, [\n  step('step1'),\n  step('step2'),\n  step('step3')\n]).onCancel((cancellation) =\u003e this.handleCancel(cancellation));\n```\n\nIf using inside of an `Ember.Object`, you could make this a computed property:\n\n```js\nexport default Component.extend({\n  myPipeline: computed(function() {\n    return pipeline(this, [\n      step('step1'),\n      step('step2'),\n      step('step3')\n    ]).onCancel((cancellation) =\u003e this.handleCancel(cancellation));\n  })\n});\n```\n\n`step` receives either a method name as a string, or a function:\n\n```js\n[step('step1'), step(x =\u003e x * x)];\n```\n\nIn a `step` function, return `CANCEL()` to abort the pipeline:\n\n```js\n{\n  step1() {\n    return CANCEL('optional reason, can be any type');\n  }\n}\n```\n\nThen, to run the pipeline, get the reference to it and `perform` it:\n\n```js\nget(this, 'myPipeline').perform(...args);\npipelineInstance.perform(...args);\n```\n\nYou can compose new pipelines at runtime. For example:\n\n```js\nexport default Component.extend({\n  makePipeline(steps) {\n    return pipeline(this, steps)\n      .onCancel((cancellation) =\u003e this.handleCancel(cancellation));\n  },\n\n  // ...\n\n  actions: {\n    normal(...args) {\n      return this.makePipeline([step('step1'), step('step2')]).perform(...args);\n    },\n\n    reverse(...args) {\n      return this.makePipeline([step('step2'), step('step1')]).perform(...args);\n    }\n  }\n});\n```\n\nAfter a pipeline has been performed, you can get derived state:\n\n```js\nget(this, 'myPipeline').perform(1, 2, 3);\nget(this, 'myPipeline.successfulSteps.length'); // 2\nget(this, 'myPipeline.cancelledSteps.length'); // 1\nget(this, 'myPipeline.successfulSteps'); // array of successful Steps\nget(this, 'myPipeline.cancelledSteps'); // array of cancelled Steps\n```\n\n## API\n\nBecause features are still in flux, detailed API docs are coming soon!\n\n## Roadmap\n\n- [ ] Support `ember-concurrency` tasks\n\n## Installation\n\n* `git clone \u003crepository-url\u003e` this repository\n* `cd ember-pipeline`\n* `npm install`\n* `bower install`\n\n## Running\n\n* `ember serve`\n* Visit your app at [http://localhost:4200](http://localhost:4200).\n\n## Running Tests\n\n* `npm test` (Runs `ember try:each` to test your addon against multiple Ember versions)\n* `ember test`\n* `ember test --server`\n\n## Building\n\n* `ember build`\n\nFor more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoteto%2Fember-pipeline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoteto%2Fember-pipeline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoteto%2Fember-pipeline/lists"}