From 8e450c53fdb72536f6a2947283138b94c09951eb Mon Sep 17 00:00:00 2001 From: Peng Lv Date: Fri, 5 Dec 2014 16:06:14 +0800 Subject: [PATCH 1/4] Use $evalAsync to update ngModel instead of $apply. --- src/ui-ace.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui-ace.js b/src/ui-ace.js index e0f27ac..74e5a3a 100644 --- a/src/ui-ace.js +++ b/src/ui-ace.js @@ -207,9 +207,9 @@ angular.module('ui.ace', []) onChange: function (callback) { return function (e) { var newValue = session.getValue(); - if (newValue !== scope.$eval(attrs.value) && !scope.$$phase && !scope.$root.$$phase) { + if (newValue !== scope.$eval(attrs.value)) { if (angular.isDefined(ngModel)) { - scope.$apply(function () { + scope.$evalAsync(function () { ngModel.$setViewValue(newValue); }); } From c161a1a82c539a24acfc3cf0b4b1bae73c4e2b98 Mon Sep 17 00:00:00 2001 From: Peng Lv Date: Mon, 8 Dec 2014 13:16:31 +0800 Subject: [PATCH 2/4] update angularjs dependencies --- README.md | 2 +- bower.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e653660..3c73d97 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This directive allows you to add [ACE](http://ajaxorg.github.io/ace/) editor ele ## Requirements -- AngularJS +- AngularJS >=1.1.0 - [Ace 1.x](https://github.com/ajaxorg/ace-builds/) diff --git a/bower.json b/bower.json index 0434118..429e8d6 100644 --- a/bower.json +++ b/bower.json @@ -16,7 +16,7 @@ "package.json" ], "dependencies": { - "angular": "~1.x", + "angular": "^1.1.x", "ace-builds": "~1.1.1" }, "devDependencies": { From 687d77e25beb217fffdedaa406c5e1ad80174d03 Mon Sep 17 00:00:00 2001 From: Peng Lv Date: Tue, 9 Dec 2014 11:24:44 +0800 Subject: [PATCH 3/4] fix unit test errors --- bower.json | 2 +- src/ui-ace.js | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/bower.json b/bower.json index 429e8d6..a1dc642 100644 --- a/bower.json +++ b/bower.json @@ -20,6 +20,6 @@ "ace-builds": "~1.1.1" }, "devDependencies": { - "angular-mocks": "~1.x" + "angular-mocks": "1.3.0" } } diff --git a/src/ui-ace.js b/src/ui-ace.js index 74e5a3a..9a53935 100644 --- a/src/ui-ace.js +++ b/src/ui-ace.js @@ -209,9 +209,8 @@ angular.module('ui.ace', []) var newValue = session.getValue(); if (newValue !== scope.$eval(attrs.value)) { if (angular.isDefined(ngModel)) { - scope.$evalAsync(function () { - ngModel.$setViewValue(newValue); - }); + ngModel.$setViewValue(newValue); + !scope.$$phase && !scope.$root.$$phase && scope.$digest(); } executeUserCallback(callback, e, acee); } From 4bf562e345e3346f07f2875be4fe1ab3ebea22ce Mon Sep 17 00:00:00 2001 From: Peng Lv Date: Tue, 9 Dec 2014 13:42:32 +0800 Subject: [PATCH 4/4] update test code --- bower.json | 2 +- test/ace.spec.js | 40 ++++++++++++++++++++-------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/bower.json b/bower.json index a1dc642..429e8d6 100644 --- a/bower.json +++ b/bower.json @@ -20,6 +20,6 @@ "ace-builds": "~1.1.1" }, "devDependencies": { - "angular-mocks": "1.3.0" + "angular-mocks": "~1.x" } } diff --git a/test/ace.spec.js b/test/ace.spec.js index 627771e..08a2545 100644 --- a/test/ace.spec.js +++ b/test/ace.spec.js @@ -29,7 +29,7 @@ describe('uiAce', function () { spyOn(window.ace, 'require'); }); it('should not call ace/config if a workerPath is not defined', function () { - $compile('
')(scope); + $compile('
')(scope); expect(_ace.require).not.toHaveBeenCalledWith('ace/config'); }); }); @@ -45,7 +45,7 @@ describe('uiAce', function () { spyOn(window.ace, 'require').andReturn(_config); }); it('should call ace/config if a workerPath is defined', function () { - $compile('
')(scope); + $compile('
' )(scope); expect(_ace.require).toHaveBeenCalledWith('ace/config'); }); }); @@ -62,7 +62,7 @@ describe('uiAce', function () { spyOn(_config, 'set'); }); it('should call "set" if workerPath is defined', function () { - $compile('
')(scope); + $compile('
')(scope); expect(_config.set).toHaveBeenCalled(); }); }); @@ -75,7 +75,7 @@ describe('uiAce', function () { spyOn(window.ace, 'require'); }); it('should not call window.ace.require if there is no "require" option', function () { - $compile('
')(scope); + $compile('
')(scope); expect(_ace.require).not.toHaveBeenCalled(); }); }); @@ -88,7 +88,7 @@ describe('uiAce', function () { spyOn(window.ace, 'require'); }); it('should call "window.ace.require" for each option in "require"', function () { - $compile('
')(scope); + $compile('
')(scope); expect(_ace.require).toHaveBeenCalled(); expect(_ace.require.callCount).toEqual(2); }); @@ -105,7 +105,7 @@ describe('uiAce', function () { }); }); it('should not call "setOption" if no "advanced" options are given.', function () { - $compile('
')(scope); + $compile('
')(scope); var session = _ace.getSession(); spyOn(session, 'setOption'); expect(session.setOption).not.toHaveBeenCalled(); @@ -123,7 +123,7 @@ describe('uiAce', function () { }); }); it('Given advanced option is null if not defined.', function () { - $compile('
')(scope); + $compile('
')(scope); var session = _ace.getSession(); spyOn(session, 'getOption'); expect(session.getOption).toBeDefined(); @@ -142,7 +142,7 @@ describe('uiAce', function () { }); }); it('given advanced options are properly defined.', function () { - $compile('
')(scope); + $compile('
')(scope); var session = _ace.getSession(); spyOn(session, 'getOption'); expect(session.getOption).toBeDefined(); @@ -154,7 +154,7 @@ describe('uiAce', function () { it('should not throw an error when window.ace is defined', function () { function compile() { - $compile('
')(scope); + $compile('
')(scope); } expect(compile).not.toThrow(); @@ -163,7 +163,7 @@ describe('uiAce', function () { it('should watch the uiAce attribute', function () { spyOn(scope, '$watch'); - $compile('
')(scope); + $compile('
')(scope); expect(scope.$watch).toHaveBeenCalled(); }); }); @@ -181,21 +181,21 @@ describe('uiAce', function () { }); it('should call ace.edit', function () { - $compile('
')(scope); + $compile('
')(scope); expect(_ace).toBeDefined(); }); describe('options', function () { describe('passed', function () { it('should show the showGutter', function () { - $compile('
')(scope); + $compile('
')(scope); expect(_ace.renderer).toBeDefined(); expect(_ace.renderer.getShowGutter()).toBeTruthy(); }); }); describe('global', function () { it('should hide the showGutter', function () { - $compile('
')(scope); + $compile('
')(scope); expect(_ace.renderer).toBeDefined(); expect(_ace.renderer.getShowGutter()).toBeFalsy(); }); @@ -205,7 +205,7 @@ describe('uiAce', function () { scope.aceLoaded = function () { }; spyOn(scope, 'aceLoaded'); - $compile('
')(scope); + $compile('
')(scope); expect(scope.aceLoaded).toHaveBeenCalled(); expect(scope.aceLoaded).toHaveBeenCalledWith(_ace); }); @@ -214,21 +214,21 @@ describe('uiAce', function () { describe('readOnly', function () { it('should read only option true', function () { - $compile('
')(scope); + $compile('
')(scope); scope.$apply(); expect(_ace.getReadOnly()).toBeTruthy(); - $compile('
')(scope); + $compile('
')(scope); scope.$apply('foo = true'); expect(_ace.getReadOnly()).toBeTruthy(); }); it('should read only option false', function () { - $compile('
')(scope); + $compile('
')(scope); scope.$apply(); expect(_ace.getReadOnly()).toBeFalsy(); - $compile('
')(scope); + $compile('
')(scope); scope.$apply(); expect(_ace.getReadOnly()).toBeFalsy(); - $compile('
')(scope); + $compile('
')(scope); expect(_ace.getReadOnly()).toBeFalsy(); scope.$apply('foo = true'); expect(_ace.getReadOnly()).toBeTruthy(); @@ -285,7 +285,7 @@ describe('uiAce', function () { }); it('should call destroy when the element is removed', function () { - var element = $compile('
')(scope); + var element = $compile('
')(scope); spyOn(_ace, 'destroy').andCallThrough(); spyOn(_ace.session, '$stopWorker').andCallThrough();