Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/coffee/utils/array-sync.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ angular.module('uiGmapgoogle-maps').factory 'uiGmaparray-sync', [
set_at: (index) ->
return if isSetFromScope #important to avoid cyclic forever change loop watch to map event change and back
value = mapArray.getAt(index)
return unless value
return if not value.lng or not value.lat
return unless value and value.lng and value.lat
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be shorter via, return unless value?.lng and value?.lat

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nmccready, nice! isn't as readable though. plus it checks for the existence of value twice. to clarify:

original code:
return if value is undefined
return if value doesn't have a lng or it doesn't have a ltd

my code:
return unless there is a value defined with lng and ltd

your code:
return unless value is defined and has a lng and value is defined and has a lat

what do u say?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't say it is less readable, if your used to coffee this is a goto staple for me know. It eliminates tons of redundant code.

Also unless I normally use only if there is one variable to check for truthyness but your case works cause your using a bunch of ands. Basically unless has unexpected behavior at times where it really means if !(value and value.lng and value.lat).

Anyway this one liner is not worth arguing about.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this would have been best return unless value?.lng and value.lat then one check for existence and it satisfies me and u.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, @nmccready ! :)

geojsonArray[index][1] = value.lat()
geojsonArray[index][0] = value.lng()

Expand Down