Skip to content

Commit a5c9e53

Browse files
committedJun 4, 2013
Created Errors Package
0 parents  commit a5c9e53

6 files changed

+86
-0
lines changed
 

‎errors.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Meteor.errors = new Meteor.Collection(null);
2+
3+
Meteor.Errors = {
4+
throw : function(message) {
5+
Meteor.errors.insert({message: message, seen: false});
6+
},
7+
clear: function() {
8+
Meteor.errors.remove({seen: true});
9+
}
10+
}

‎errors_list.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<template name="meteorErrors">
2+
{{#each errors}}
3+
{{> meteorError}}
4+
{{/each}}
5+
</template>
6+
7+
<template name="meteorError">
8+
<div class="alert alert-error">
9+
<button type="button" class="close" data-dismiss="alert">&times;</button>
10+
{{message}}
11+
</div>
12+
</template>

‎errors_list.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Template.meteorErrors.helpers({
2+
errors: function() {
3+
return Meteor.errors.find();
4+
}
5+
});
6+
7+
Template.meteorError.rendered = function() {
8+
var error = this.data;
9+
Meteor.defer(function() {
10+
Meteor.errors.update(error._id, {$set: {seen: true}});
11+
});
12+
};

‎errors_tests.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Tinytest.add("Errors collection works", function(test) {
2+
test.equal(Meteor.errors.find({}).count(), 0);
3+
4+
Meteor.Errors.throw ('A new error!');
5+
test.equal(Meteor.errors.find({}).count(), 1);
6+
7+
Meteor.errors.remove({});
8+
});
9+
10+
Tinytest.addAsync("Errors template works", function(test, done) {
11+
Meteor.Errors.throw ('A new error!');
12+
test.equal(Meteor.errors.find({seen: false}).count(), 1);
13+
14+
// render the template
15+
OnscreenDiv(Spark.render(function() {
16+
return Template.meteorErrors();
17+
}));
18+
19+
// wait a few milliseconds
20+
Meteor.setTimeout(function() {
21+
test.equal(Meteor.errors.find({seen: false}).count(), 0);
22+
test.equal(Meteor.errors.find({}).count(), 1);
23+
Meteor.Errors.clear();
24+
test.equal(Meteor.errors.find({seen: true}).count(), 0);
25+
done();
26+
}, 500);
27+
});

‎package.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Package.describe({
2+
summary: "A pattern to display application errors to the user"
3+
});
4+
5+
Package.on_use(function(api, where) {
6+
api.use(['minimongo', 'mongo-livedata', 'templating'], 'client');
7+
api.add_files(['errors.js', 'errors_list.html', 'errors_list.js'], 'client');
8+
});
9+
10+
Package.on_test(function(api) {
11+
api.use('errors', 'client');
12+
api.use(['tinytest', 'test-helpers'], 'client');
13+
api.add_files('errors_tests.js', 'client');
14+
});

‎smart.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "errors",
3+
"description": "A pattern to display application errors to the user",
4+
"homepage": "https://github.com/tmeasday/meteor-errors",
5+
"author": "Tom Coleman <tom@thesnail.org>",
6+
"version": "0.1.0",
7+
"git": "https://github.com/tmeasday/meteor-errors.git",
8+
"packages": {
9+
10+
}
11+
}

0 commit comments

Comments
 (0)
Please sign in to comment.