tracker issue : CF-3748332

select a category, or use search below
(searches all categories and all time range)
Title:

CFClient does not support arrayEach() / arrayFilter() / arraySort() / arrayMap() / arrayReduce()

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/

Reporter/Name(from Bugbase): Adam Cameron / Adam Cameron (Adam Cameron)

Created: 04/23/2014

Components: Language

Versions: 11.0

Failure Type:

Found In Build/Fixed In Build: PublicBeta /

Priority/Frequency: Major / Some users will encounter

Locale/System: ALL / Platforms All

Vote Count: 0

Listed in the version 11.0.03.292480 Issues Fixed doc
SSIA.

Needless to say it should also support the member-function version of these too.

-- 
Adam

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3748332

External Customer Info:
External Company:  
External Customer Name: Adam Cameron.
External Customer Email:  
External Test Config: My Hardware and Environment details:

Attachments:

Comments:

Added support for arrayEach() / arraySort() / arrayMap() / arrayReduce() functions in CFCLIENT Supported member functions are: each, map, reduce arrayFilter and arraySort member function will not be supported as it conflicts with Javascript filter function (Comment added from ex-user id:prk)
Comment by Adobe D.
12571 | September 03, 2014 06:59:13 AM GMT
So your compiler cannot distinguish between a method call on a CFML object, and one on a JS object?
Comment by External U.
12572 | September 04, 2014 02:15:51 AM GMT
Hello?
Comment by External U.
12573 | November 10, 2014 04:48:58 PM GMT
Hi Priyatharsini and Adam, I've verified that CFClient supports the following in CF11 Update 3 (11,0,03,292024(PreRelease)): arrayEach(), myArray.each(), arrayFilter(), myArray.filter(), arrayMap(), myArray.map(), arrayReduce(), myArray.reduce() Can arraySort() and myArray.sort() please also be supported for consistency and to avoid confusion? Thanks! -Aaron
Comment by External U.
12574 | November 13, 2014 08:56:15 AM GMT
Here's the repro code I used (had to comment-out the cfclient tags in order to run the arraySort()/myArray.sort() section: <cfclient> <cfscript> myArray = listToArray("1,,2,,3"); arrayEach(myArray, function(a){writeOutput(a&'a');});//displays 1a2a3a writeOutput('<br>'); myArray.each(function(a){writeOutput(a&'a');});//displays 1a2a3a myArray = listToArray("1,,2,,3"); writeOutput('<br>'); writeOutput(arrayToList(arrayFilter(myArray, function(){return true;})));//displays 1,2,3 writeOutput('<br>'); writeOutput(arrayToList(myArray.filter(function(){return true;})));//displays 1,2,3 /*myArray = listToArray("c,,a,,b"); arraySort(myArray, "textnocase"); writeOutput('<br>'); writeOutput(arrayToList(myArray));//displays a,b,c (doesn't work in cfclient) myArray.sort("textnocase", "desc");//displays c,b,a (doesn't work in cfclient) writeOutput('<br>'); writeOutput(arrayToList(myArray));*/ myArray = listToArray("1,,2,,3"); writeOutput('<br>'); writeOutput(arrayToList(arrayMap(myArray, function(){return "a";})));//displays a,a,a writeOutput('<br>'); writeOutput(arrayToList(myArray.map(function(){return "a";})));//displays a,a,a myArray = listToArray("1,,2,,3", ",", true); writeOutput('<br>'); writeOutput(arrayReduce(myArray, function(result,item,index,array){return arrayLen(array);}, 0));//displays 5 writeOutput('<br>'); writeOutput(myArray.reduce(function(result,item,index,array){return arrayLen(array);}, 0));//displays 5 </cfscript> </cfclient>
Comment by External U.
12575 | November 13, 2014 08:57:13 AM GMT
we do not support arraySort() method as member function as it conflicts with built-in Java script sort method. So if arraySort() is invoked as member function result will be sort done by javascript and it will not match CFML sorting behavior. (Comment added from ex-user id:sandeepp)
Comment by Adobe D.
12576 | November 14, 2014 02:10:31 AM GMT
That's a bit limp, Sandeep. You compile (or transpile) the CFML first, so if someone's written myArray.sort() in their CFML, you can transpile that to myArray._sort() in the resultant JS. No conflict. It's *far* worse to have most of these methods handled by one language, and some others handled by another. Especially ones which a dev might not initially notice because the code still "works". That's before we get to the point that the whole *idea* of <cfclient> is that one writes CFML instead of JS.
Comment by External U.
12577 | November 14, 2014 02:31:35 AM GMT
Hi Sandeep, I agree w/ Adam. Having some methods handled by CF and some by JS is just asking for trouble. Since CF generates the HTML, it can write myArray._sort() if developer wrote myArray.sort() w/in <cfclient>. Then, no more conflict. (basically, again, yes I agree) Thanks!, -Aaron
Comment by External U.
12578 | November 14, 2014 02:51:32 AM GMT
"That's before we get to the point that the whole *idea* of <cfclient> is that one writes CFML instead of JS." Ah, yes, very good point Adam. So arraySort() and myArray.sort() need to be added. Thanks!, -Aaron
Comment by External U.
12579 | November 14, 2014 02:56:01 AM GMT
This is still not fixed in CF11 Update 3 (11,0,03,292245(PreRelease)). The following repro outputs nothing unless the <cfclient> tags are removed: <cfclient> <cfscript> myArray = listToArray("c,,a,,b"); arraySort(myArray, "textnocase"); writeOutput(arrayToList(myArray));//outside cfclient, displays a,b,c (inside cfclient, displays nothing) myArray.sort("textnocase", "desc"); writeOutput('<br>' & arrayToList(myArray));//outside cfclient, displays c,b,a (inside cfclient, displays nothing) </cfscript> </cfclient> Thanks!, -Aaron
Comment by External U.
12580 | November 21, 2014 08:18:21 AM GMT
This is still not fixed in CF11 Update 3 (11,0,03,292480). The following repro outputs nothing unless the <cfclient> tags are removed: <cfclient> <cfscript> myArray = listToArray("c,,a,,b"); arraySort(myArray, "textnocase"); writeOutput(arrayToList(myArray));//outside cfclient, displays a,b,c (inside cfclient, displays nothing) myArray.sort("textnocase", "desc"); writeOutput('<br>' & arrayToList(myArray));//outside cfclient, displays c,b,a (inside cfclient, displays nothing) </cfscript> </cfclient> Thanks!, -Aaron
Comment by External U.
12581 | December 02, 2014 11:26:32 PM GMT
I see this code is working fine for me on this build 292480. Please let me know, is there any thing missing from my side. arraySort() method as member function will be supported from next update. (Comment added from ex-user id:prk)
Comment by Adobe D.
12582 | December 03, 2014 12:40:34 AM GMT
Hi Priyatharsini, Ah, I see arraySort() works now in cfclient. Very cool. Since this ticket also covers arraySort() as member function, and since it won't be supported till next update, should this ticket be re-opened until arraySort() is supported as a member function? If not, is there a public ticket # we can track for that issue? Thanks!, -Aaron
Comment by External U.
12583 | December 03, 2014 03:21:24 AM GMT
Hi Aaron, Thanks for confirming ! I have logged a different bug for this Arraysort() as member function(https://watsonexp.corp.adobe.com/#bug=CF-3861391). -Priya (Comment added from ex-user id:prk)
Comment by Adobe D.
12584 | December 03, 2014 04:49:34 AM GMT
Hi Priya, You're very welcome, and I've voted for #CF-3861391. Thanks!, -Aaron
Comment by External U.
12585 | December 03, 2014 05:38:09 AM GMT
Verified myArray.sort() is fixed in CF11 Update 5 (build 11,0,05,293506) per ticket CF-3861391. myArray.sort("textnocase", "desc") is rewritten as myArray._cfsort("textnocase","desc") Makes me wonder tho (and this was something I thought about when <cfclient> was introduced), what happens when a CF code is using a JS function w/in cfclient and then later CF introduces its own function of the same name? Thanks!, -Aaron
Comment by External U.
12586 | November 23, 2015 05:59:18 AM GMT
*when CF code is
Comment by External U.
12587 | November 23, 2015 05:59:55 AM GMT