john-n-smith / mvcobject-js Goto Github PK
View Code? Open in Web Editor NEWAn implementation of the KVO pattern, inspired by Google Maps API v3 MVCObject class
An implementation of the KVO pattern, inspired by Google Maps API v3 MVCObject class
var abc = new MVCObject;
abc.set('testing', 'hi');
abc.unbind('testing');
> Uncaught TypeError: Cannot use 'in' operator to search for '__my_index' in
null
from line 235 of source.
I would personally expect unbinding an unbound property to do nothing. The code
appears to want to throw a different error: '"' + key + '" is not a bound
property.' but the code never gets there.
The key from line 235 is this clause:
'__my_index' in this[key]
...where this[key] is apparently null. Adding a check for this[key] resolves
the issue.
Again, I would prefer (and have modified the source locally) to not throw an
error at all in this scenario.
Original issue reported on code.google.com by [email protected]
on 3 Dec 2012 at 11:27
I added a comment to line 193 indicating I think there is mistake:
http://code.google.com/p/mvcobject-js/source/browse/trunk/MVCObject.js#193
The comment appears to indicate that one isn't allowed to set a property that
isn't already set, but then how does one set a value the first time?
Original issue reported on code.google.com by [email protected]
on 16 Sep 2012 at 4:23
What steps will reproduce the problem?
var abc = new MVCObject;
abc.property = null;
abc.property_changed = function() { console.log('triggered'); };
abc.set('property', 'value1');
> triggered
abc.property_changed = null;
abc.set('property', 'value2');
> "TypeError: Property 'property_changed' of object #<MVCObject> is not a
function" from line ~225
I expect no error when my callback is null. Instead I get an error that
basically says the code tried to run "null".
Using latest version 0.21. By replacing the following line:
if(key + '_changed' in this) this[key + '_changed']();
with this:
if(typeof this[key + '_changed'] === 'function') this[key + '_changed']();
I was able to fix the error. Also verified that an actual observer function
there will run.
Cheers,
Dave
Original issue reported on code.google.com by [email protected]
on 26 Jan 2013 at 1:07
What steps will reproduce the problem?
1. only execute sample code
2.
3.
What is the expected output? What do you see instead?
Uncaught TypeError: Property 'foo_changed' of object #<MVCObject> is not a
function
What version of the product are you using? On what operating system?
lastest version MVCObject-source-0.20.js
Please provide any additional information below.
need to modify code in MVCObject.prototype.set function
for(var i in this[key].__shared_object.__observers)
{
if(this[key].__shared_object.__observers[i] === null) continue;
//ADDED 2012.10.10 addition code Trigger the observer's observer's callbacks
if( this[key].__shared_object.__observers[i].key + '_changed' in this[key].__shared_object.__observers[i].obj)
this[key].__shared_object.__observers[i].obj[this[key].__shared_object.__observers[i].key + '_changed']();
}
Original issue reported on code.google.com by [email protected]
on 10 Oct 2012 at 7:29
Attachments:
What steps will reproduce the problem?
var abc = new MVCObject();
abc.set('newProperty', 'anything')
> Cannot set value for undefined property "newProperty".
There's no reason that this error needs to be thrown. If I remove this line
(line 193) entirely, the object behaves as expected – my value gets set
(down on line 222), and line 225 calls my callback (unless it's null - see
issue 4).
We've discussed elsewhere that this (awesome) library throws a lot of errors.
In my experience this is a seriously annoying design flaw. Unbinding a property
that isn't bound throws an error on line 296, but the result of an unbind
operation - having something that isn't bound - can be achieved by simply
returning.
Original issue reported on code.google.com by [email protected]
on 26 Jan 2013 at 1:29
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.