Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a sponsors page #4

Merged
merged 19 commits into from
Jan 15, 2018
Merged

Add a sponsors page #4

merged 19 commits into from
Jan 15, 2018

Conversation

AverageMarcus
Copy link
Member

Add a page showing all our past an present sponsors.

Wait until #3 is complete so previous sponsors are included.

@@ -43,5 +43,15 @@ module.exports = {
});

return Object.values(speakers);
},
'getSponsors': function(events) {
const sponsors = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor Missing semicolon; 'cos, you know, semicolons are super important 😆

Copy link
Member Author

Choose a reason for hiding this comment

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

oh the shame! 😞

});
});

return Object.values(sponsors);
Copy link
Contributor

Choose a reason for hiding this comment

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

Style There's nothing wrong with this function but it duplicates the getSpeakers function differing only in that it is sponsors and not speakers.

I'm okay with the duplication 'cos the algorithm expressed in the functions is straightforward... but we are a tech meetup that's about JS. As such, maybe we should not have such dupes: extracting a shared function that can be called by both is easy enough.

Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

💯 Agree! I'll refactor! :)

});
});
return Object.values(deduped);
}
Copy link
Contributor

@richdouglasevans richdouglasevans Jan 14, 2018

Choose a reason for hiding this comment

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

There's nothing wrong here: I'm just sharing.

You may wish to consider using an explicitly curried function here: doing so will lead to less code to write at the places where this dedupe function is used.

Consider:

// existing way
'getSponsors': function(events) {
    return dedupe(events, 'sponsors');
}

// curried way
'getSponsors': dedupe('sponsors')

The latter version is smaller with no loss of clarity: we're deduping the sponsors. It dispenses with the creation of a "bridging" function that's there just to invoke the dedupe function.

The latter version is achieved with this small change to the dedupe function:

const dedupe = key => events => {
  const deduped = {};
  events && events.forEach(event => {
    event[key] && event[key].forEach(item => {
      deduped[item.name] = item;
    });
  });
  return Object.values(deduped);
}

I've swapped the order of the arguments around so that events comes last. I've also transformed the function from a binary one that accepts both key and events into a sequence of unary functions. The first unary function takes a key and returns another unary function that takes the events.

The latter point is important because the event handler is looking for a unary function to pass the events to. This refactoring makes it possible to invoke the dedupe function with the significant bit -- the key, currently one of sponsors or speakers -- and get a function that's ready for invocation by the framework.

Thoughts? It's no biggie, just sharing 😄

@AverageMarcus AverageMarcus merged commit 9aefab5 into master Jan 15, 2018
@AverageMarcus AverageMarcus deleted the sponsors_page branch January 15, 2018 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants