Comments (15)
Successfully tested in Lucee 4.5.3 !
from underscorecf.
Good to know!
from underscorecf.
I ran the unit tests on CF 11 and all passed.
Aria Media Sagl
Via Rompada 40
6987 Caslano
Switzerland
+41 (0)91 600 9601
+41 (0)76 303 4477 cell
skype: ariamedia
On Wed, Dec 16, 2015 at 9:14 PM, Russ [email protected] wrote:
Good to know!
—
Reply to this email directly or view it on GitHub
#43 (comment)
.
from underscorecf.
@dnando Great! Now we just need to get the Travis CI stuff updated
from underscorecf.
Russ,
Running the unit tests on Lucee 4.5.2.018, I get a single error on
testBind, as below:
Can't cast Complex Object Type Struct to String
Use Built-In-Function "serialize(Struct):String" to create a String from
Struct
/Users/nando/sites/UnderscoreCF/mxunit_tests/functionsTest.cfc (28)
/Users/nando/sites/UnderscoreCF/Underscore.cfc (1356)
/Users/nando/sites/UnderscoreCF/mxunit_tests/functionsTest.cfc (34)
/Users/nando/sites/mxunit/framework/TestCase.cfc (141)
/Users/nando/sites/mxunit/framework/decorators/DataProviderDecorator.cfc
(31)
/Users/nando/sites/mxunit/framework/TestSuiteRunner.cfc (105)
/Users/nando/sites/mxunit/framework/TestSuiteRunner.cfc (55)
/Users/nando/sites/mxunit/framework/TestSuite.cfc (131)
/Users/nando/sites/mxunit/runner/DirectoryTestSuite.cfc (37)
/Users/nando/sites/UnderscoreCF/mxunit_tests/runTests.cfm (8)
Here's the test, with line 28 in italics.
public void function testBind() {
var context = new MyClass({name : 'moe'});
var func = function(arg, this) {
// writeDump(arg);
if (isDefined("this.name")) {
return "name: " & this.name;
}
else if (structKeyExists(arguments, "arg")) {
return "name: " & arguments.arg;
}
else {
throw "oops";
}
};
var bound = _.bind(func, context);
assertEquals('name: moe', bound(), 'can bind a function to a context');
// TODO: once OO-style binding is ready
// bound = _(func).bind(context);
// equal('name: moe', bound(), 'can do OO-style binding');
bound = _.bind(func, {}, 'curly');
assertEquals('name: curly', bound(), 'can bind without specifying a
context');
func = function(salutation, name) { return salutation & ': ' & name; };
func = _.bind(func, {}, 'hello');
assertEquals('hello: moe', func('moe'), 'the function was partially
applied in advance');
var func2 = _.bind(func, {}, 'curly');
assertEquals('hello: curly', func2(), 'the function was completely
applied in advance');
var func = function(salutation, firstname, lastname) { return salutation
& ': ' & firstname & ' ' & lastname; };
func = _.bind(func, {}, 'hello', 'moe', 'curly');
assertEquals('hello: moe curly', func(), 'the function was partially
applied in advance and can accept multiple arguments');
}
Aria Media Sagl
Via Rompada 40
6987 Caslano
Switzerland
+41 (0)91 600 9601
+41 (0)76 303 4477 cell
skype: ariamedia
On Thu, Dec 17, 2015 at 8:23 PM, Russ [email protected] wrote:
@dnando https://github.com/dnando Great! Now we just need to get the
Travis CI stuff updated—
Reply to this email directly or view it on GitHub
#43 (comment)
.
from underscorecf.
Thanks for testing that out. Looks like that's the same error that Travis gets on the Railo 4.1+ and Lucee 4.5.1+.
I remember trying to resolve this issue when it first occurred, but was unable to figure it out at the time. I should probably give it another shot!
from underscorecf.
Hey,
I think I might have figured out something related. Between JRE7 and JRE8 java changed the algorithm for iterating over HashMaps. In either case, you can't rely on the order of struct keys. It would appear that underscore, by using the for ... in syntax over a struct, is relying on the order of keys.
In memoize
we ultmately call map
in the hasher
and then pluck the first value. Since the returning array from map
is being built by "for...in" looping through the keys of the arguments, the order of the array is unpredictable -- yet we are always expecting the first element to be a simple value calling _.first( .toArray( x ) )
. This ultimately throws Can't cast Complex Object Type String or some variation of that type of error because the first element of the array could be a complex object and we are immediately trying to use that first value as the key in a StructKeyExists
in memoize.
It's certainly not the value you think it will be.
from underscorecf.
Ah, that makes sense. I can't think of a good way to resolve this yet, given that the behavior in UnderscoreJS relies on arguments
to be ordered (even though you normally wouldn't expect that of JS objects either). Any ideas are appreciated.
from underscorecf.
In Lucee 5 and prob in ACF12 you can specify ordered structs.
-- Arthur
On Thu, Sep 8, 2016 at 6:28 PM, Russ [email protected] wrote:
Ah, that makes sense. I can't think of a good way to resolve this yet,
given that the behavior in UnderscoreJS relies on arguments to be ordered
(even though you normally wouldn't expect that of JS objects either). Any
ideas are appreciated.—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#43 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJoQssQKBYlSD9OJi40FG9c_9x3FH5Bks5qoIvxgaJpZM4B1zc7
.
from underscorecf.
Instead of passing in arguments directly to hasher, I did var _args = CreateObject("java", "java.util.LinkedHashMap").init( arguments )
before calling hasher(x)
in
memoize
and that preserved order. There is going to be a bit of a
performance penalty there. Alternatively, in this case, the structs come in
with numeric keys that retain position so you could simply do a
structKeyArray, sort the array, and then loop over that array. That
solution assumes that the struct has keys that indicate sort order.
If you always knew that you were going to be working with the arguments struct, you could just automatically assume that you can loop from 1 to structCount, appending from the array from object[n].
On Thu, Sep 8, 2016 at 6:38 PM, Arthur [email protected] wrote:
In Lucee 5 and prob in ACF12 you can specify ordered structs.
-- Arthur
On Thu, Sep 8, 2016 at 6:28 PM, Russ [email protected] wrote:
Ah, that makes sense. I can't think of a good way to resolve this yet,
given that the behavior in UnderscoreJS relies on arguments to be ordered
(even though you normally wouldn't expect that of JS objects either). Any
ideas are appreciated.—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#43 (comment)
245761670>,
or mute the thread
<https://github.com/notifications/unsubscribe-
auth/AAJoQssQKBYlSD9OJi40FG9c_9x3FH5Bks5qoIvxgaJpZM4B1zc7>.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#43 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABMyw3U9VJE6aO_bHDkOkT7DVcu367tQks5qoI5ygaJpZM4B1zc7
.
from underscorecf.
Alright, so it sounds like the high-level options are:
- Use ordered structs, but the drawback is that it would require ACF12/Lucee5.
- Use
java.util.linkedHashMap
, but the drawbacks there are: adding a dependency to Java internals and potentially degrading performance (depending on the implementation?). - Write some special-case handling for the arguments struct (not sure if there's a way to test a struct for whether it is an arguments struct).
Not sure about which of these are viable or not, just providing a summary here.
from underscorecf.
I would think to start with #2 until we see that performance is an issue?
from underscorecf.
I'd open to any solution, really. We can always optimize later if necessary.
from underscorecf.
Yeah, let's roll with that solution.
from underscorecf.
#54 was submitted back in September, been waiting for someone to make the test cases pass for all of the engines
from underscorecf.
Related Issues (20)
- Make toQuery(arrayOfStructs) handle variable-size structs
- Docs CSS and formatting HOT 8
- XML support for toQuery() HOT 1
- Add toXml(collection, [*elementNames])
- Add examples for object()
- Compatibility: Railo for-in loops on structs are wrong
- xml support for _.size()
- _.type(variable)
- _.toArray(string) should return an array of characters
- Port 1.4.4 changes HOT 1
- Port changes to _.uniq and _.times
- Add _.REReplace(string, regex, callback, [scope], [context])
- implement _.transform(collection, callback, accumulator, context) : any (from lo-dash)
- toArray() uses for-in loop on a list variable which is not supported HOT 4
- Get Travis-CI working HOT 4
- variables._ is undefined HOT 5
- is this still an active project? HOT 1
- Publish to ForgeBox.io? HOT 3
- Calling slice with a "to" 1 value greater than the length of the array causes an error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from underscorecf.