|
1 | 1 | /** |
2 | 2 | * @author Jason Dobry <jason.dobry@gmail.com> |
3 | 3 | * @file js-data-angular.js |
4 | | -* @version 2.0.0-alpha.1-0 - Homepage <http://js-data-angular.pseudobry.com/> |
| 4 | +* @version 2.0.0-alpha.1-0 - Homepage <http://www.js-data.io/js-data-angular/> |
5 | 5 | * @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/> |
6 | 6 | * @license MIT <https://github.com/js-data/js-data-angular/blob/master/LICENSE> |
7 | 7 | * |
8 | | -* @overview Data store for Angular.js. |
| 8 | +* @overview Angular wrapper for js-data.js. |
9 | 9 | */ |
10 | 10 | (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ |
| 11 | +/*jshint loopfunc:true*/ |
11 | 12 | (function (window, angular, undefined) { |
12 | 13 | 'use strict'; |
13 | 14 |
|
|
16 | 17 | project: 'js-data-http', |
17 | 18 | name: 'http', |
18 | 19 | class: 'DSHttpAdapter' |
| 20 | + }, |
| 21 | + { |
| 22 | + project: 'js-data-localstorage', |
| 23 | + name: 'localstorage', |
| 24 | + class: 'DSLocalStorageAdapter' |
| 25 | + }, |
| 26 | + { |
| 27 | + project: 'js-data-localforage', |
| 28 | + name: 'localforage', |
| 29 | + class: 'DSLocalForageAdapter' |
| 30 | + }, |
| 31 | + { |
| 32 | + project: 'js-data-firebase', |
| 33 | + name: 'firebase', |
| 34 | + class: 'DSFirebaseAdapter' |
19 | 35 | } |
20 | 36 | ]; |
21 | 37 |
|
|
34 | 50 |
|
35 | 51 | if (Adapter) { |
36 | 52 | adapter.loaded = true; |
37 | | - angular.module(adapter.project, ['ng']).provider(adapter.class + 'Provider', function () { |
| 53 | + angular.module(adapter.project, ['ng']).provider(adapter.class, function () { |
38 | 54 | var _this = this; |
39 | 55 | _this.defaults = {}; |
40 | 56 | _this.$get = [function () { |
|
64 | 80 | throw new Error('js-data must be loaded!'); |
65 | 81 | } |
66 | 82 |
|
| 83 | + var functionsToWrap = [ |
| 84 | + 'compute', |
| 85 | + 'digest', |
| 86 | + 'eject', |
| 87 | + 'inject', |
| 88 | + 'link', |
| 89 | + 'linkAll', |
| 90 | + 'linkInverse', |
| 91 | + 'unlinkInverse' |
| 92 | + ]; |
| 93 | + |
67 | 94 | angular.module('js-data', ['ng']) |
68 | 95 | .factory('DSUtils', JSData.DSUtils) |
69 | 96 | .factory('DSErrors', JSData.DSErrors) |
|
80 | 107 |
|
81 | 108 | _this.defaults = {}; |
82 | 109 |
|
83 | | - deps.push(function () { |
| 110 | + function load() { |
| 111 | + var args = Array.prototype.slice.call(arguments); |
| 112 | + var $rootScope = args[args.length - 1]; |
84 | 113 | var store = new JSData.DS(_this.defaults); |
| 114 | + var originals = {}; |
85 | 115 |
|
86 | 116 | for (var i = 0; i < adapters.length; i++) { |
87 | 117 | if (adapters[i].loaded) { |
88 | 118 | store.registerAdapter(adapters[i].name, arguments[i]); |
89 | 119 | } |
90 | 120 | } |
91 | 121 |
|
92 | | - return new JSData.DS(_this.defaults); |
93 | | - }); |
| 122 | + for (i = 0; i < functionsToWrap.length; i++) { |
| 123 | + originals[functionsToWrap[i]] = store[functionsToWrap[i]]; |
| 124 | + store[functionsToWrap[i]] = function () { |
| 125 | + var args = arguments; |
| 126 | + if (!$rootScope.$$phase) { |
| 127 | + return $rootScope.$apply(function () { |
| 128 | + return originals[functionsToWrap[i]].apply(store, args); |
| 129 | + }); |
| 130 | + } |
| 131 | + return originals[functionsToWrap[i]].apply(store, args); |
| 132 | + }; |
| 133 | + } |
| 134 | + |
| 135 | + return store; |
| 136 | + } |
| 137 | + |
| 138 | + deps.push('$rootScope'); |
| 139 | + deps.push(load); |
94 | 140 |
|
95 | 141 | _this.$get = deps; |
96 | 142 | }); |
|
0 commit comments