{"id":18962254,"url":"https://github.com/lipp/angular-jet","last_synced_at":"2026-04-02T01:30:18.139Z","repository":{"id":25572256,"uuid":"29005961","full_name":"lipp/angular-jet","owner":"lipp","description":"Angular Binding for Jet Realtime Bus","archived":false,"fork":false,"pushed_at":"2015-04-15T08:45:00.000Z","size":416,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T06:04:39.701Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lipp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-09T07:33:09.000Z","updated_at":"2015-04-15T08:44:34.000Z","dependencies_parsed_at":"2022-09-07T15:13:31.801Z","dependency_job_id":null,"html_url":"https://github.com/lipp/angular-jet","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Fangular-jet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Fangular-jet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Fangular-jet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Fangular-jet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lipp","download_url":"https://codeload.github.com/lipp/angular-jet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239958310,"owners_count":19724926,"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-08T14:15:45.968Z","updated_at":"2026-04-02T01:30:18.076Z","avatar_url":"https://github.com/lipp.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# angular-jet\nAngular Binding for [Jet Realtime Bus](http://jetbus.io/).\n\n[![Build Status](https://travis-ci.org/lipp/angular-jet.svg)](https://travis-ci.org/lipp/angular-jet?branch=master)\n[![Coverage Status](https://coveralls.io/repos/lipp/angular-jet/badge.svg)](https://coveralls.io/r/lipp/angular-jet)\n\n# Example usage\n\nThis is a classic todo app. Realtime with Jet. Changes of the model are synced\nautomatically! No need to mess around with ng-change.\n\n```html\n  \u003cbody ng-controller=\"TodoCtrl\"\u003e\n    \u003cdiv\u003e\n\n      \u003c!-- Add a random todo button --\u003e\n      \u003cbutton ng-click=\"addRandomTodo()\"\u003eAdd a Random Todo\u003c/button\u003e\n\n    \u003c/div\u003e\n\n    \u003c!-- Add todo input --\u003e\n    \u003cform ng-submit=\"addTodo()\"\u003e\n      \u003cinput placeholder=\"What needs to be done?\" ng-model=\"newTodo\" autofocus\u003e\n    \u003c/form\u003e\n\n    \u003c!-- Todo list --\u003e\n    \u003cdiv id=\"todos\"\u003e\n      \u003cdiv ng-cloak ng-repeat=\"todo in todos | orderBy: '$value.id'\"\u003e\n        \u003cinput type=\"checkbox\" ng-model=\"todo.$value.completed\" /\u003e\n        \u003cinput ng-model=\"todo.$value.title\" /\u003e\n        \u003cbutton ng-click=\"removeTodo(todo.$value)\"\u003eRemove\u003c/button\u003e\n        \u003cspan ng-if=\"todo.$error\" ng-click=\"todo.$revert()\"\u003e{{todo.$error.data.message}} Click to revert.\u003c/span\u003e\n      \u003c/div\u003e\n    \u003c/div\u003e\n\n    \u003c!-- Custom JS --\u003e\n    \u003cscript src=\"todo.js\" defer\u003e\u003c/script\u003e\n  \u003c/body\u003e\n```\n\n```javascript\nvar app = angular.module('todo',['jet']);\napp. controller('TodoCtrl', function Todo($scope, $jet) {\n  // Create a Jet peer\n  var peer = new $jet.$Peer({\n    url: 'ws://localhost:1234',\n    scope: $scope\n  });\n\n  // Get the todos as an array\n  $scope.todos = peer.$fetch({\n    path: {\n      startsWith: 'todo/#'\n    }\n  });\n\n  /* Adds a new todo item */\n  $scope.addTodo = function() {\n    if ($scope.newTodo !== '') {\n      peer.$call('todo/add', [{title: $scope.newTodo, completed: false}]);\n      $scope.newTodo = '';\n    }\n  };\n\n  /* Adds a random todo item */\n  $scope.addRandomTodo = function () {\n    $scope.newTodo = 'Todo ' + new Date().getTime();\n    $scope.addTodo();\n  }\n\n  /* Removes the todo item with the inputted ID */\n  $scope.removeTodo = function(todo) {\n    peer.$call('todo/remove', [todo]);\n  };\n\n});\n\n```\n\n\n# API\n\n## $jet.$Peer([options]) // function (ctor)\n\nConstructs a new Peer.\n\n`options` is optional and can contain:\n - `url` : The websocket url of the Jet Daemon (default: 'ws://localhost:11123')\n - `scope` : The scope to attach this Peer to, e.g. If the Peer belongs to a controller (default: `$rootScope`)\n - `timeout` : The connect timeout in ms (default: `5000`)\n\n```javascript\n// example from todo app\nvar app = angular.module('todo',['jet']);\napp. controller('TodoCtrl', function Todo($scope, $jet) {\n  // Create a Jet peer\n  var peer = new $jet.$Peer({\n    url: 'ws://localhost:1234',\n    scope: $scope\n  });\n...\n```\n\nThe Peer and all fetches created by a peer instance are attached to to scope provided.\nCleanup is performed automatically during scope $on $destroy. If no scope is provided\n(if the Peer is used from within a service) it defaults to $rootScope.\n\n## peer.$connected // Promise\n\nPromise which gets resolved when the peer is successfully connected to the Jet\nDaemon or rejected if the connect timeout expires.\n\n## peer.$closed // Promise\n\nPromise which gets resolved then the Peer connection to the daemon has been closed.\n\n## {Promise} completed = peer.$set(path, value, [valueAsResult]) // function\n\nSets the State specified by path to the given value. Returns a promise which gets\nresolved if setting the State value returned no error.\n\nThe resolve callback argument is true or - if valueAsResult=true - the new State's value.\nNote that depending on the owning Peer's implementation may implement custom behaviour when setting the\nState and the State may have actually another value then the one passed to set as\nargument.\n\nIn case of an error, the promise gets rejected with the error as callback argument.\nThe error is a JSON-RPC error Object (containing: code, message and optionally data).\n\n## {Promise} completed = peer.$call(path, [object_or_array]) // function\n\nCalls the Method specified by path with the given argument. The argument must be either\nan Object or an Array or undefined.\n\nReturns a promise resolving with the result as argument or rejecting with the error\nas argument. The error is an JSON-RPC error object (containing: code, message and optionally data).\n\n\n## {FetchedArray} fa = peer.$fetch(rule, [scope]) // function\n\nFetches all States matching the fetch rule. Fetching is like having a realtime query,\nwhich updates as the queried data gets modified, added or removed.\nThe return value is an auto-synced FetchArray containing all matching States.\n\nThe supported fields of rule are:\n\n- `path`: {Object, Optional} For path based fetches\n- `value`: {Object, Optional} For value based fetches\n- `valueField`: {Object, Optional} For valuefield based fetches\n- `sort`: {Object, Optional} For sorted fetches\n\nA scope can be provided optionally and defaults to the peer's scope.\n\n```javascript\n// example from todo app\n$scope.todos = peer.$fetch({\n  path: {\n    startsWith: 'todo/#'\n  }\n});\n\n```\n\n```javascript\n// fetch the top ten female players\n// a player may look like this:\n// {\n//  name: 'Foo',\n//  gender: 'male',\n//  score: 12345\n// }\n$scope.topFemalePlayers = peer.$fetch({\n  path: {\n    startsWith: 'players/#'\n  },\n  valueField: {\n    gender: {\n      equals: 'female'\n    }\n  },\n  sort: {\n    from: 1,\n    to: 10,\n    byValueField: {\n      score: 'number'\n    }\n  }\n});\n\n```\n\n\n# FetchArray\n\nA FetchArray can be created by calling peer.$fetch(...). In addition to the Javascript Array\nfunctionality (containing the FetchedStates), methods are exposed. The FetchArray is automatically\nremoved ($unfetched) during scope $on $destroy.\n\n## {Promise} unfetched = FetchArray.$unfetch() // function\n\nUnregisters the fetch expression at the Jet Daemon. Returns a promise which is\nresolved when the unregistration process is complete. This function is automatically\ncalled with scope $on $destroy.\n\n## FetchArray.$autoSave(enable) // function\n\nEnables or disables auto-save functionality of the contained State $values. E.g. if enabled,\nthere is no need to call state.$save() on model change.\n\n## FetchArray.$debounce(ms) // function\n\nSets the scope $apply debounce time for remote State changes. Defaults to 50ms.\n\n## FetchArray.$ready // Promise\n\nPromise which gets resolved as soon as the fetch expression has been successfully\nadded to the Jet Daemon.\n\n# FetchedState\n\nFetchedStates are the content of a FetchArray. They cannot be created \"manually\".\n\n## FetchedState.$value // any non-function type\n\nThe State's (Jet) value. Can be of any type. If the corresponding $fetcher is\nconfigured as autoSync (default), this $value is automatically $watched within the scope\nand changes are applied as the model changes. That means you MUST NOT call FetchedStates.$save()\nto sync changes to the (remote) State.\n\nWhile changes are applied FetchedState.$value may differ from FetchedState.$fetchedValue.\n\n## FetchedState.$path // string\n\nThe State's (Jet) path. The $path is a string and identifies the State.\n\n## {Promise} completed = FetchedState.$save([valueAsResult]) // function\n\nSets the (remote) State to the current $value.\n\nBehaves exactly like peer.$set(FetchedState.$path, FetchedState.$value, valueAsResult).\n\n## FetchedState.$index // number\n\nNumber, only present for \"sorted\" FetchArray. The index within [sort.from,sort.to] range.\n\n## FetchedState.$error // Object\n\nError object containing code, message and optionally data of a failed\nFetchedState.$save operation. The FetchedState.$save operation may be triggered\nby local model changes to FetcheState.$value.\n\n## FetchedState.$fetchedValue // any non-function type\n\nThe current fetched value, which may differ from a not-yet applied change of FetchedState.$value.\n\n## FetchedState.$revert() // function\n\nLocally sets FetchedState.$value to FetchedState.$fetchedValue and deletes\nFetchedState.$error.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flipp%2Fangular-jet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flipp%2Fangular-jet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flipp%2Fangular-jet/lists"}