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

aeq.forEach does not work with ScriptUI container children array #28

Open
runegan opened this issue Jul 27, 2017 · 4 comments
Open

aeq.forEach does not work with ScriptUI container children array #28

runegan opened this issue Jul 27, 2017 · 4 comments
Labels
bug Something isn't working minor

Comments

@runegan
Copy link
Member

runegan commented Jul 27, 2017

Original report by Rune Gangsø (Bitbucket: runegan, GitHub: runegan).


Example:

var win = aeq.ui.createWindow()
win.addButton()
win.addButton()
win.addButton()
aeq.forEach( win.get().children, function( key, value ) {
    alert( key + value )
})

This only alerts ones, with the text length3.

Caused by bad checking of array type in aeq.forEach

@runegan
Copy link
Member Author

runegan commented May 2, 2018

Original comment by Zack Lovatt (Bitbucket: zlovatt, GitHub: zlovatt).


One workflow solution--

aeq.arrayEx(win.get().children).forEach( function( child ) {
    alert( child.text )
});

or to solve the specific issue, we can change aeq.forEach array detection from...
if ( obj && Object.prototype.toString.call( obj ) === '[object Array]' )

to

if ( obj && ( Object.prototype.toString.call( obj ) === '[object Array]' || obj.constructor.name === 'Collection' ) )

Thoughts @runegan ?

@runegan
Copy link
Member Author

runegan commented May 2, 2018

Original comment by Rune Gangsø (Bitbucket: runegan, GitHub: runegan).


That looks good to me. Does all js objects have the constructor property?

@runegan
Copy link
Member Author

runegan commented May 2, 2018

Original comment by Zack Lovatt (Bitbucket: zlovatt, GitHub: zlovatt).


Everything I've seen does, but not sure about everything. Issue is that with prototype.toString.call(whatever) some array-ish elements return [object Array] and others include a string of the elements within them (maybe only ESTK's Collections). My suggestion above seemed robust, but better to double-check.

@runegan
Copy link
Member Author

runegan commented May 2, 2018

Original comment by Rune Gangsø (Bitbucket: runegan, GitHub: runegan).


Ok, as long as we don't get a 'something' does not have a property constructor error we're good.

@runegan runegan added minor bug Something isn't working labels Feb 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working minor
Projects
None yet
Development

No branches or pull requests

1 participant