-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Events System #37
Comments
@ajoslin, decided against it? Seems worth doing to me. |
Woohoo, feedback! Thanks @tlvince. I will probably do it within the next few weeks, when I use this on a new project that requires minimum-minimum filesize. |
Hey @ajoslin, even though I am not currently using the events, I was thinking about using them in my current project. I need to achieve the following: Let's say I have a data entry form with several input fields. Each field's data gets saved separately on blur by calling some server API. Now I'd like to show an activity indicator next to each field when data is being saved. I have only one service method that is responsible for saving the data. My idea was to use one single promise tracker there that will be given the current form attribute name in the Do you think sth like this would be still doable without those event hooks? Or maybe there is an even simpler solution ... maybe I could just use one (dynamically named) promise tracker for each individual form input. I would really appreciating your feedback on this! Thanks. |
I think one promiseTracker per input would be the simplest, (there is very little overhead per promiseTracker). You could do it this way, if I added $scope.model = {
foo: 'foo',
bar: 'BAR',
baz: 'bazzy'
};
var trackers = {};
angular.forEach($scope.model, function(value, key) {
trackers[key] = promiseTracker.register(key, {/*options*/});
});
$scope.submit = function(key) {
trackers[key].addPromise(SubmitService.submit(key, $scope.model[key]));
};
$scope.$on('$destroy', function() {
angular.forEach(trackers, function(value, key) {
promiseTracker.deregister(key);
});
}); |
Thanks for the feedback, that sounds plausible! |
Will add a few more tests and push today: register and deregister functions, and no events system. The old version will still be available for people who don't want to migrate their code. |
BREAKING CHANGE: The events system has been removed. That means you can no longer do `.on()` and `.off()`. In essence, events were a poor way of doing 'hooks' on promises. See [this issue](#37) for more information. [Open an issue of your own](https://github.com/ajoslin/angular-promise-tracker/issues) if you were using events and need help migrating to use anotehr method. Check [the README](https://github.com/ajoslin/angular-promise-tracker/tree/master/README.md) for details on the current API for promiseTracker.
Landed in v2.0.0-beta1. See the changelog. https://github.com/ajoslin/angular-promise-tracker/blob/master/CHANGELOG.md |
Also, filesize shaved by almost 40% with the new change. :-) |
Bumped to v2.0.0-beta2 with a fix. every time!
Also going to reopen this issue for problems. |
👍 |
We could break things even more (and simplify them) before v2.0.0. We could remove the whole id system altogether.
The main downside is this requires people to create a service to store their trackers. Or store them on rootScope. Both of which I usually do already. This means we could get rid of the whole weird register and deregister system. We could still have a destroy() function for manual tracker cleanup. |
Also we could remove the It's nice because it can save you a tiny bit of code.. but the downside is it makes people usually put $scope.register = function(user, pass) {
var loginPromise = AuthService.register(user, pass).then(function() {
return AuthService.login(user, pass);
}).then(function() {
return doSomethingElse();
}).then(function() {
alert('login done!');
});
$scope.tracker.addPromise(loginPromise);
}; |
@ajoslin The last example you posted looks almost like the way I am already doing it – so removing the ID stuff and the But if I understand your proposal correctly, then this would break for example angular-busy, which relies on being able to identify a certain tracker by its ID, wouldn't it? |
ok I will leave it for now since it does have uses! |
It seems to me the events system is a useless bloat feature: I added it at the start just 'as a thing' (I mean the
tracker.on('done', cb)
kind of thing).If we remove it, promise-tracker can become a good micro-library that does only what you need.
The text was updated successfully, but these errors were encountered: