Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

observejs会触发多次事件 #5

Open
leoxoocanada opened this issue Apr 20, 2016 · 3 comments
Open

observejs会触发多次事件 #5

leoxoocanada opened this issue Apr 20, 2016 · 3 comments

Comments

@leoxoocanada
Copy link

leoxoocanada commented Apr 20, 2016

在使用observejs时为了跟原生的Object.observe 兼容,我写了如下代码

                objectObserve = Object.observe || function (obj, fun){
                        observe(obj, function (name, value, oldValue) {
                                fun && fun([{
                                    type: 'update',
                                    name: name,
                                    oldValue: oldValue
                                }]);
                        })
                    };

结果发现fun回调会被执行多次,目前我的办法是加一个定时器,100ms内只允许执行一次,这样可以解决多次触发的问题,但不太理解为什么会有触发多次的问题?

@dntzhang
Copy link
Collaborator

dntzhang commented Apr 20, 2016

observe(obj,xx)执行过多少次就会触发多少次。你重复绑定了多次? @gafish

@leoxoocanada
Copy link
Author

最终我们用了 https://github.com/MaxArt2501/object-observe 这个方案,不用改业务代码,引入库文件即可,改动最小

@dntzhang
Copy link
Collaborator

那个库好像是用定时器 @gafish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants