Extracted out seen() support, made it a mixin.
Showing
10 changed files
with
187 additions
and
0 deletions
.gitignore
0 → 100644
Gruntfile.js
0 → 100644
This diff is collapsed.
Click to expand it.
bower.json
0 → 100644
1 | { | ||
2 | "name": "backbone-seen", | ||
3 | "version": "0.0.0", | ||
4 | "authors": [ | ||
5 | "Adam Heath <doogie@brainfood.com>" | ||
6 | ], | ||
7 | "main": [ | ||
8 | "src/scripts/backbone-seen.js" | ||
9 | ], | ||
10 | "private": true, | ||
11 | "ignore": [ | ||
12 | "**/.*", | ||
13 | "node_modules", | ||
14 | "src/lib", | ||
15 | "test" | ||
16 | ], | ||
17 | "dependencies": { | ||
18 | "underscore": "~1.6.0", | ||
19 | "backbone": "~1.1.0", | ||
20 | "requirejs": "~2.1.10" | ||
21 | } | ||
22 | } |
package.json
0 → 100644
1 | { | ||
2 | "name": "backbone-seen", | ||
3 | "version": "0.0.0", | ||
4 | "main": [ | ||
5 | "src/scripts/backbone-seen.js" | ||
6 | ], | ||
7 | "dependencies": { | ||
8 | "underscore": "~1.6.0", | ||
9 | "backbone": "~1.1.0", | ||
10 | "requirejs": "~2.1.10" | ||
11 | }, | ||
12 | "devDependencies": { | ||
13 | "bower-requirejs": "~0.9.2", | ||
14 | "grunt": "~0.4.1", | ||
15 | "grunt-contrib-copy": "~0.4.1", | ||
16 | "grunt-contrib-concat": "~0.3.0", | ||
17 | "grunt-contrib-uglify": "~0.2.0", | ||
18 | "grunt-contrib-jshint": "~0.7.0", | ||
19 | "grunt-contrib-cssmin": "~0.7.0", | ||
20 | "grunt-contrib-connect": "~0.5.0", | ||
21 | "grunt-contrib-clean": "~0.5.0", | ||
22 | "grunt-contrib-htmlmin": "~0.1.3", | ||
23 | "grunt-bower-install": "~0.7.0", | ||
24 | "grunt-contrib-imagemin": "~0.2.0", | ||
25 | "grunt-contrib-watch": "~0.5.2", | ||
26 | "grunt-rev": "~0.1.0", | ||
27 | "grunt-autoprefixer": "~0.5.0", | ||
28 | "grunt-usemin": "~0.1.10", | ||
29 | "grunt-mocha": "~0.4.0", | ||
30 | "grunt-newer": "~0.6.0", | ||
31 | "grunt-svgmin": "~0.2.0", | ||
32 | "grunt-concurrent": "~0.4.0", | ||
33 | "load-grunt-tasks": "~0.2.0", | ||
34 | "time-grunt": "~0.2.0", | ||
35 | "jshint-stylish": "~0.1.3", | ||
36 | "grunt-contrib-requirejs": "~0.4.0", | ||
37 | "grunt-bower-requirejs": "~0.8.4", | ||
38 | "grunt-template-jasmine-istanbul": "~0.2.6", | ||
39 | "grunt-template-jasmine-requirejs": "~0.1.10", | ||
40 | "grunt-contrib-jasmine": "~0.5.3" | ||
41 | }, | ||
42 | "engines": { | ||
43 | "node": ">=0.8.0" | ||
44 | } | ||
45 | } |
src/scripts/backbone-seen.js
0 → 100644
1 | define( | ||
2 | [ | ||
3 | 'underscore', | ||
4 | ], | ||
5 | function( | ||
6 | _ | ||
7 | ) { | ||
8 | 'use strict'; | ||
9 | |||
10 | var seen = function(attrName, wasSeen) { | ||
11 | if (this._seen === undefined) { | ||
12 | this._seen = {}; | ||
13 | } | ||
14 | if (attrName === undefined) { | ||
15 | return _.keys(_.clone(this._seen)); | ||
16 | } | ||
17 | if (wasSeen) { | ||
18 | this._seen[attrName] = true; | ||
19 | } else if (wasSeen === false) { | ||
20 | delete this._seen[attrName]; | ||
21 | } else { | ||
22 | return this._seen[attrName]; | ||
23 | } | ||
24 | return this; | ||
25 | }; | ||
26 | |||
27 | return { | ||
28 | mixin: function(modelClass) { | ||
29 | modelClass.prototype.seen = seen; | ||
30 | return modelClass; | ||
31 | }, | ||
32 | }; | ||
33 | } | ||
34 | ); |
src/scripts/config.js
0 → 100644
src/scripts/jquery.js
0 → 100644
1 | define([], {}); |
src/scripts/main.js
0 → 100644
test/specs/backbone-seen.spec.js
0 → 100644
1 | define(function(require) { | ||
2 | 'use strict'; | ||
3 | |||
4 | var BackboneSeen = require('backbone-seen'); | ||
5 | var Backbone = require('backbone'); | ||
6 | |||
7 | describe('BackboneSeen', function() { | ||
8 | it('exists', function() { | ||
9 | expect(BackboneSeen).toBeTruthy(); | ||
10 | expect(Backbone.Model.prototype.seen).toBeUndefined(); | ||
11 | }); | ||
12 | }); | ||
13 | describe('BackboneSeen', function() { | ||
14 | var Base, Parent, Child; | ||
15 | beforeEach(function() { | ||
16 | Base = Backbone.Model.extend(); | ||
17 | Parent = Base.extend(); | ||
18 | Child = Parent.extend(); | ||
19 | }); | ||
20 | it('mixin', function() { | ||
21 | expect(Base.prototype.seen).toBeUndefined(); | ||
22 | expect(Parent.prototype.seen).toBeUndefined(); | ||
23 | expect(Child.prototype.seen).toBeUndefined(); | ||
24 | var base = new Base({a: '1'}); | ||
25 | var parent = new Parent({a: '1'}); | ||
26 | var child = new Child({b: 'c'}); | ||
27 | expect(base.seen).toBeUndefined(); | ||
28 | expect(parent.seen).toBeUndefined(); | ||
29 | expect(child.seen).toBeUndefined(); | ||
30 | Parent = BackboneSeen.mixin(Parent); | ||
31 | var seen = parent.seen; | ||
32 | expect(base.seen).toBeUndefined(); | ||
33 | expect(seen).toEqual(jasmine.any(Function)); | ||
34 | expect(child.seen).toBe(parent.seen); | ||
35 | }); | ||
36 | it('seen', function() { | ||
37 | Parent = BackboneSeen.mixin(Parent); | ||
38 | var parent = new Parent({a: '1'}); | ||
39 | expect(parent.seen()).toEqual([]); | ||
40 | expect(parent.seen('a')).toBe(undefined); | ||
41 | expect(parent.seen('a', true)).toBe(parent); | ||
42 | expect(parent.seen()).toEqual(['a']); | ||
43 | expect(parent.seen('a')).toBe(true); | ||
44 | expect(parent.seen('a', false)).toBe(parent); | ||
45 | expect(parent.seen()).toEqual([]); | ||
46 | expect(parent.seen('a')).toBe(undefined); | ||
47 | }); | ||
48 | }); | ||
49 | }); |
-
Please register or sign in to post a comment