can.compute error with can.Observe #436

Merged
merged 1 commit into from Jul 18, 2013

Conversation

Projects
None yet
2 participants
@daffl
Contributor

daffl commented Jul 17, 2013

https://github.com/bitovi/canjs/blob/master/observe/compute/compute.js#L338

if( can.Observe.__reading && canReadForChangeEvent) {
    can.Observe.__reading(computed,'change');
}

This conditional assumes can.Observe exists. Just need an extra if(can.Observe && can.Observe.__reading...

Noting this until I get back to it(unless someone beats me to this!)

@khoinguyen

This comment has been minimized.

Show comment
Hide comment
@khoinguyen

khoinguyen Jun 30, 2013

I also got the same problem, especially when use with AMD RequireJS, and optimised by r.js

$ r.js -o build.js 

Tracing dependencies for: main

/Project/www/scripts/main-built.js
----------------
/Project/www/scripts/less.js
/Project/www/scripts/sockjs-0.3.4.min.js
/Project/www/scripts/jquery-1.8.2.min.js
/Project/www/scripts/jquery.ba-hashchange-1.3.js
/Project/www/scripts/vertxbus.js
/Project/www/scripts/can/util/can.js
/Project/www/scripts/can/util/array/each.js
/Project/www/scripts/can/util/jquery.js
/Project/www/scripts/can/util/library.js
/Project/www/scripts/can/view.js
/Project/www/scripts/can/util/string.js
/Project/www/scripts/can/util/bind.js
/Project/www/scripts/can/observe/compute.js <<< Note here, No can/observe was included
/Project/www/scripts/can/view/elements.js
/Project/www/scripts/can/view/scanner.js
/Project/www/scripts/can/view/node_lists.js
/Project/www/scripts/can/view/live.js
/Project/www/scripts/can/view/render.js
/Project/www/scripts/can/view/ejs.js
/Project/www/scripts/can/construct.js
/Project/www/scripts/can/control.js
/Project/www/scripts/domReady.js
domReady!
/Project/www/scripts/app/widget/ChatWidget.js
/Project/www/scripts/app/main.js
/Project/www/scripts/main.js

Result: Uncaught TypeError: Cannot read property '__reading' of undefined

I fixed this issue in can/observe/compute.js:

define(["can/util/library", "can/util/bind"], function(can, bind) {

change to

define(["can/util/library", "can/util/bind", "can/observe"], function(can, bind) {

Output of r.js

$r.js -o build.js 

Tracing dependencies for: main

/Project/www/scripts/main-built.js
----------------
/Project/www/scripts/less.js
/Project/www/scripts/sockjs-0.3.4.min.js
/Project/www/scripts/jquery-1.8.2.min.js
/Project/www/scripts/jquery.ba-hashchange-1.3.js
/Project/www/scripts/vertxbus.js
/Project/www/scripts/can/util/can.js
/Project/www/scripts/can/util/array/each.js
/Project/www/scripts/can/util/jquery.js
/Project/www/scripts/can/util/library.js
/Project/www/scripts/can/view.js
/Project/www/scripts/can/util/string.js
/Project/www/scripts/can/util/bind.js
/Project/www/scripts/can/construct.js
/Project/www/scripts/can/observe.js <<< Note here, can/observe.js was included in the optimised file
/Project/www/scripts/can/observe/compute.js
/Project/www/scripts/can/view/elements.js
/Project/www/scripts/can/view/scanner.js
/Project/www/scripts/can/view/node_lists.js
/Project/www/scripts/can/view/live.js
/Project/www/scripts/can/view/render.js
/Project/www/scripts/can/view/ejs.js
/Project/www/scripts/can/control.js
/Project/www/scripts/domReady.js
domReady!
/Project/www/scripts/app/widget/ChatWidget.js
/Project/www/scripts/app/main.js
/Project/www/scripts/main.js

I also got the same problem, especially when use with AMD RequireJS, and optimised by r.js

$ r.js -o build.js 

Tracing dependencies for: main

/Project/www/scripts/main-built.js
----------------
/Project/www/scripts/less.js
/Project/www/scripts/sockjs-0.3.4.min.js
/Project/www/scripts/jquery-1.8.2.min.js
/Project/www/scripts/jquery.ba-hashchange-1.3.js
/Project/www/scripts/vertxbus.js
/Project/www/scripts/can/util/can.js
/Project/www/scripts/can/util/array/each.js
/Project/www/scripts/can/util/jquery.js
/Project/www/scripts/can/util/library.js
/Project/www/scripts/can/view.js
/Project/www/scripts/can/util/string.js
/Project/www/scripts/can/util/bind.js
/Project/www/scripts/can/observe/compute.js <<< Note here, No can/observe was included
/Project/www/scripts/can/view/elements.js
/Project/www/scripts/can/view/scanner.js
/Project/www/scripts/can/view/node_lists.js
/Project/www/scripts/can/view/live.js
/Project/www/scripts/can/view/render.js
/Project/www/scripts/can/view/ejs.js
/Project/www/scripts/can/construct.js
/Project/www/scripts/can/control.js
/Project/www/scripts/domReady.js
domReady!
/Project/www/scripts/app/widget/ChatWidget.js
/Project/www/scripts/app/main.js
/Project/www/scripts/main.js

Result: Uncaught TypeError: Cannot read property '__reading' of undefined

I fixed this issue in can/observe/compute.js:

define(["can/util/library", "can/util/bind"], function(can, bind) {

change to

define(["can/util/library", "can/util/bind", "can/observe"], function(can, bind) {

Output of r.js

$r.js -o build.js 

Tracing dependencies for: main

/Project/www/scripts/main-built.js
----------------
/Project/www/scripts/less.js
/Project/www/scripts/sockjs-0.3.4.min.js
/Project/www/scripts/jquery-1.8.2.min.js
/Project/www/scripts/jquery.ba-hashchange-1.3.js
/Project/www/scripts/vertxbus.js
/Project/www/scripts/can/util/can.js
/Project/www/scripts/can/util/array/each.js
/Project/www/scripts/can/util/jquery.js
/Project/www/scripts/can/util/library.js
/Project/www/scripts/can/view.js
/Project/www/scripts/can/util/string.js
/Project/www/scripts/can/util/bind.js
/Project/www/scripts/can/construct.js
/Project/www/scripts/can/observe.js <<< Note here, can/observe.js was included in the optimised file
/Project/www/scripts/can/observe/compute.js
/Project/www/scripts/can/view/elements.js
/Project/www/scripts/can/view/scanner.js
/Project/www/scripts/can/view/node_lists.js
/Project/www/scripts/can/view/live.js
/Project/www/scripts/can/view/render.js
/Project/www/scripts/can/view/ejs.js
/Project/www/scripts/can/control.js
/Project/www/scripts/domReady.js
domReady!
/Project/www/scripts/app/widget/ChatWidget.js
/Project/www/scripts/app/main.js
/Project/www/scripts/main.js

daffl added a commit that referenced this pull request Jul 18, 2013

Merge pull request #436 from bitovi/compute-error-436
can.compute error with can.Observe

@daffl daffl merged commit 5469f73 into master Jul 18, 2013

1 check passed

default The Travis CI build passed
Details

@daffl daffl deleted the compute-error-436 branch Jul 18, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment