isc30 / linq-collections

Strongly typed Linq and Collections implementation for Javascript and TypeScript (ECMAScript 5)
https://www.npmjs.com/package/linq-collections
MIT License
119 stars 12 forks source link

Firebase Javascript Objects? #13

Closed c0ldfront closed 6 years ago

c0ldfront commented 6 years ago

Hi,

I am trying to use your library with Google Firebase Realtime Database JavaScript objects. I am having an issue well trying to create a new Dictionary<string, Object> which doesn't seem to be working well with JavaScript objects. The object I am trying to parse looks like this.

var objdict: Dictionary<string, Object> = new Dictionary<string, Object>(event[0]);

->Object {-L-j7Z4jxiQiSAKBGxSD: Object, -L-j7Z4lKxlERKPCtKLk: Object}
---> -L-j7Z4jxiQiSAKBGxSD:Object {ExpirationDate: "9999-12-31T00:00:00.000Z", Name: "Object 1", StartDate: "2017-12-07T04:00:58.990Z"}
---> -L-j7Z4lKxlERKPCtKLk:Object {ExpirationDate: "2017-12-08T04:00:58.990Z", Name: "Object 2", StartDate: "2017-12-07T04:00:58.990Z"}

I was stepping into the code to try and figure out what was the issue, because I am pretty new in JavaScript and noticed. in the Collections.js compiled version It is trying to find the length of the keyValuePairs.length which doesn't seem to work with JavaScriptObjects? If i do Object.keys(keyValuePairs).length it will find the correct length for the total amount of keys within that object.

Am I using dictionaries worry or is there anyway I can use your current linq-collection with javascript objects and or is there a way I can fix this issue so I can use linq-collection?

Thanks for your help.

isc30 commented 6 years ago

Hi, current implementation expects an array in the Dictionary constructor: Array<IKeyValue<TKey, TValue>> I think you are right, a pure object-based constructor will be really nice feature to have. I'll work on it, thanks a lot for the feedback 👍

isc30 commented 6 years ago

Hi, I just created/pushed the new function Dictionary.fromJsObject<TValue>(object: any) Please tell me if it fits your requirements, thanks 😄

c0ldfront commented 6 years ago

Wow isc30! Thanks for such a fast response on this matter! Yeah it works perfectly, I just tested it and works perfectly. I am using it like so.

var categories_record: IDictionary<string, Category> = Dictionary.fromJsObject<Category>(event[2]);

Thanks again for responding and creating a new function so quickly.:)

isc30 commented 6 years ago

Nice to hear! 🎉 Thanks to you for feedback and support on the library 😄