Skip to content

Commit

Permalink
0.2.10 fix listenToValue leaks after remove
Browse files Browse the repository at this point in the history
  • Loading branch information
Efremov Alexey committed Apr 30, 2014
1 parent 11f2475 commit d519861
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 15 deletions.
8 changes: 6 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ module.exports = function(grunt) {
options:{
configFile: 'karma.conf.js',
runnerPort: 9999,
//browsers: ['PhantomJS'],
//browsers: ['PhantomJS'],
},
dist: {
singleRun: true
},
watch:{}
watch:{
options:{
browsers: ['Chrome'],
}
}
}
});
grunt.registerTask('build', [
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "backbone-mixin",
"version": "0.2.9",
"version": "0.2.10",
"authors": [
"[email protected]"
],
Expand Down
14 changes: 10 additions & 4 deletions build/backbone-mixin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var MixinBackbone;

MixinBackbone = function(Backbone) {
MixinBackbone.version = "0.2.9";
MixinBackbone.version = "0.2.10";
MixinBackbone = function(BaseClass) {
return BaseClass.extend({
setElement: function() {
Expand Down Expand Up @@ -64,11 +64,17 @@ MixinBackbone = function(Backbone) {
}
return (_ref = BaseClass.prototype.delegateEvents) != null ? _ref.call(this, events) : void 0;
},
listenToValue: function(obj, name, callback) {
obj.on("change:" + name, callback, this);
listenToValue: function(obj, _name, callback) {
var name;
if (/change:(.+)/.exec(_name)) {
name = RegExp.$1;
} else {
name = _name;
}
this.listenTo(obj, "change:" + name, callback);
return setTimeout(((function(_this) {
return function() {
return callback.call(_this, obj, obj.get(name));
return callback.call(_this, obj, obj.get(name), {});
};
})(this)), 0);
},
Expand Down
2 changes: 1 addition & 1 deletion build/backbone-mixin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions dist/backbone-mixin.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MixinBackbone = (Backbone)->
MixinBackbone.version = "0.2.9"
MixinBackbone.version = "0.2.10"
MixinBackbone = (BaseClass)->
BaseClass.extend
#
Expand Down Expand Up @@ -58,8 +58,12 @@ MixinBackbone = (Backbone)->
# @lang=ru Хелпер позволяет повесить слушателя на obj
# на измение значения name и сразу же вызвать callback для текущего значения
#
listenToValue:(obj, name, callback) ->
obj.on "change:#{name}", callback, this
listenToValue:(obj, _name, callback) ->
if /change:(.+)/.exec _name
name = RegExp.$1
else
name = _name
@listenTo obj, "change:#{name}", callback
setTimeout (=>
callback.call this, obj, obj.get(name),{}
), 0
Expand Down Expand Up @@ -103,6 +107,12 @@ MixinBackbone = (Backbone)->
_setCurrentView:(view)->
@_$_p.currentView = view

#
# @lang=en
#
# @lang=ru
#

show:(_view, options = {},callback)->
unless _view?
callback?()
Expand Down
4 changes: 2 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ module.exports = function(config) {
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
// - PhantomJS
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
browsers: ['Chrome'],
//browsers: ['PhantomJS'],
//browsers: ['Chrome'],
browsers: ['PhantomJS'],


// If browser does not capture in given timeout [ms], kill it
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "backbone-mixin",
"version": "0.2.9",
"version": "0.2.10",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
29 changes: 28 additions & 1 deletion test/check-listenToValue-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ describe "MixinBackbone::listenToValue",->
afterEach ->
@view.remove()

it "check old syntax",->
checkSuccess = 0
flag = false
runs =>
@view.listenToValue @view.model, "change:value",(model, value)=>
checkSuccess = value
flag = true

waitsFor (->
if flag
expect(19).toBe checkSuccess
flag
),"wait listenToValue",10



it "check listenToValue",(done)->
expect(1).toBe _.size(@results)
res = @results[0]
Expand All @@ -41,4 +57,15 @@ describe "MixinBackbone::listenToValue",->
res = @results[1]
expect(true).toBe res['size arguments']
expect(true).toBe res['model not null']
expect(true).toBe res['value equals']
expect(true).toBe res['value equals']

it "check stopListenValue",->
checkValue = 0
expect(0).toBe checkValue
@view.listenToValue @view.model, "value",(model,value)->
checkValue = value
@view.model.set {value:50}
expect(50).toBe checkValue
@view.remove()
@view.model.set {value:10}
expect(50).toBe checkValue

0 comments on commit d519861

Please sign in to comment.