BorisMoore / jsviews

Interactive data-driven views, MVVM and MVP, built on top of JsRender templates
http://www.jsviews.com/#jsviews
MIT License
857 stars 130 forks source link

TypeError: last.slice is not a function(…) #346

Closed artemipanchuk closed 8 years ago

artemipanchuk commented 8 years ago

Updated to 80, came across "TypeError: last.slice is not a function(…)". Here is call stack: TypeError: last.slice is not a function at http://localhost:53256/common/scripts/jsviews/jsviews.js:5485:19 at Number.innerObserve (http://localhost:53256/common/scripts/jsviews/jsviews.js:2840:34) at Boolean.$observe (http://localhost:53256/common/scripts/jsviews/jsviews.js:2973:24) at Function.observe_apply as _apply at observeAndBind (http://localhost:53256/common/scripts/jsviews/jsviews.js:4150:26) at Object.propertyChangeHandler (http://localhost:53256/common/scripts/jsviews/jsviews.js:3665:4) at handler (http://localhost:53256/common/scripts/jsviews/jsviews.js:5009:26) at bindDataLinkTarget (http://localhost:53256/common/scripts/jsviews/jsviews.js:5024:3) at addDataBinding (http://localhost:53256/common/scripts/jsviews/jsviews.js:4927:4) at dataLink (http://localhost:53256/common/scripts/jsviews/jsviews.js:4752:8)

image

artemipanchuk commented 8 years ago

I'm not sure, but probably the reason is your recent changes: image

BorisMoore commented 8 years ago

Thanks for calling this out...

Can you provide a jsfiddle or similar which shows this issue/bug?

There is something specific you are doing with contextual parameters which is leading to this issue. It may be a bug in JsViews, but all my test cases are working correctly.

Also, can you show your template, or at least the part that has the declaration ~foo=... of the contextual parameter that is being accessed here - and also the reference - something like ~foo.fields.name.show() ??. And can you show how you are using the getIndexOfFirst function in the template. (Is it from a library you are using?)

artemipanchuk commented 8 years ago

Hi! Thanks for very quick reply! I managed to reproduce this bug in jsfiddle.

Here it is: https://jsfiddle.net/nm3zw58b/2/

Looks like extending Array.prototype (or something like this, maybe) with functions causes adding these functions to helper array (which is defined at line 2151).

Also I figured out, that if these functions do not have any arguments, then they do not break anything.

BorisMoore commented 8 years ago

Great, that makes sense.

This will be fixed in the next update, but if you want to continue to extend Array prototype, you can use the latest version with the following additional changes:

Change line https://github.com/BorisMoore/jsviews/blob/master/jsviews.js#L2134 to:

if (key !== $expando && source.hasOwnProperty(key) && !$isFunction(prop)) {

Change line: https://github.com/BorisMoore/jsviews/blob/master/jsviews.js#L1711 to:

if (key !== "_jsvto" && paths.hasOwnProperty(key) && paths[key].length) {
artemipanchuk commented 8 years ago

Thanks for solution! Looking forward to see updates and growth of jsviews.

BorisMoore commented 8 years ago

This has been fixed in commit 81