Skip to content

Instantly share code, notes, and snippets.

@ovidiuch
Created March 1, 2013 17:24
Show Gist options
  • Save ovidiuch/5066247 to your computer and use it in GitHub Desktop.
Save ovidiuch/5066247 to your computer and use it in GitHub Desktop.
Rethink Mozaic.newDataChannels
# Refactoring the way "newDataChannels" works, maybe with an alternative
# (temporary) "createChannels" method
# With current method:
[facebook_ad_accounts,
facebook_campaigns,
facebook_ads] = Utils.newDataChannels(
'/facebook-ad-accounts': {}
'/facebook-campaigns': {}
'/facebook-ads': {}
)
widget_params =
channels:
'/facebook-ad-accounts': facebook_ad_accounts
'/facebook-campaigns': facebook_campaigns
'/facebook-ads': facebook_ads
# UGH! :(
# With new method (when passing all channels):
widget_params =
channels: Utils.createChannels(
'/facebook-ad-accounts': {}
'/facebook-campaigns': {}
'/facebook-ads': {}
)
# With new method (when they need to be sent to other widgets as well):
channels = Utils.createChannels(
'/facebook-ad-accounts': {}
'/facebook-campaigns': {}
'/facebook-ads': {}
)
widget_params =
channels: channels
# With new method (when passing only a part of the channels):
channels = Utils.createChannels(
'/facebook-ad-accounts': {}
'/facebook-campaigns': {}
'/facebook-ads': {}
)
widget_params =
channels: _.pick(channels, '/facebook-campaigns', '/facebook-ads')
# How? We just need to return the created channels inside an object with
# corresponding keys instead of an array
# Yes @aismail, we could still send "fake names", and we get rid of a lot of
# headaches in 90% of cases:
channels = Utils.createChannels(
'/facebook-ad-accounts': {}
'/facebook-campaigns': {}
'/facebook-ads': {}
)
widget_params =
channels:
'/items': channels['/facebook-ads']
@arcade
Copy link

arcade commented Mar 1, 2013

Sounds cool as far as I'm concerned, also, the destructuring statement should still work via:

{'/facebook-adds': facebook_adds} = Utils.createChannels(
  '/facebook-ad-accounts': {}
  '/facebook-campaigns': {}
  '/facebook-ads': {}
)

console.log(facebook_adds)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment