Skip to content

Instantly share code, notes, and snippets.

@ionox0
Last active January 20, 2016 02:54
Show Gist options
  • Save ionox0/6cbacb3fff5223138f13 to your computer and use it in GitHub Desktop.
Save ionox0/6cbacb3fff5223138f13 to your computer and use it in GitHub Desktop.
Switch Job Model (explanation for coffeescript --> js translation)
}.call(this), function() {
var bind = function(fn, me) {
return function() {
return fn.apply(me, arguments);
};
};
// IIFE - gets run immediately:
!function() {
var JobModel;
// JobModel is kind of like a factory for Jobs.
// We will give this function to Angular,
// It is not immediately invoked
return JobModel = function() {
var Job;
// When the factory is called by angular, the return value from the following function (an iife)
// is the constructor that gets used to create a new Job.
// The reason that there is this wrapper function (also an iife if you look below), is that
// by returning an inner constructor from this function, the inner function can have private variables
// associated with it (although we don't leverage this feature)
return Job = function() {
// Here's our job class:
function Job(data) {
this.get_years_experience_max_display = bind(this.get_years_experience_max_display, this),
this.get_years_experience_min_display = bind(this.get_years_experience_min_display, this),
this.id = data.id, this.state = data.state, this.allows_remote = data.allows_remote,
this.likes_talent = data.likes_talent, this.position = data.position, this.share_link = data.share_link,
this.posting_url = data.posting_url, this.salary_max = data.salary_max, this.salary_min = data.salary_min,
this.salary_visible = data.salary_visible, this.see_only_local_talent = data.see_only_local_talent,
this.years_experience_min = -1 === data.years_experience_min ? 0 : data.years_experience_min,
this.years_experience_max = data.years_experience_max >= 20 || -1 === data.years_experience_max ? "20+" : data.years_experience_max,
this.num_likes = data.num_likes, this.radius = 2e3 === data.radius ? "100+" : data.radius + "",
this.location = data.location, this.structured_location = data.structured_location,
data.date_added && (this.date_added = moment(data.date_added, "yyyy-MM-ddTHH:mm:ss.SSSZ")),
this.createdOn = data.created_on, this.contact_email = data.contact_email, this.perks = data.perks,
this.description = data.description, this.employer = data.employer, this.employer_profile_info = data.employer_profile_info,
this.external_source = data.external_source, this.hide_salary = data.hideSalary,
this.structured_tags = data.structured_tags, this.job_function = data.job_function,
this.new_job_function_id = data.new_job_function_id, this.company_id = data.company,
this.company_name = data.company_name, this.company_description = data.company_description,
this.company_facebook_url = data.company_facebook_url, this.company_twitter_url = data.company_twitter_url,
this.company_linkedIn_url = data.company_linkedin_url, this.company_homepage_url = data.company_homepage_url,
this.company_industry = data.company_industry, this.company_industry_id = data.company_industry_id,
this.company_latest_funding_amount = data.company_latest_funding_amount, this.company_latest_funding_date = data.company_latest_funding_date,
this.company_latest_funding_round = data.company_latest_funding_round, this.company_logo_url = data.company_logo_url,
this.company_number_of_employees = data.company_number_of_employees, this.company_total_funding_amount = data.company_total_funding_amount;
}
// Use the prototype for shared methods:
return Job.prototype.get_company = function() {
return {
company_id: this.company_id,
company_name: this.company_name,
company_industry: this.company_industry,
company_description: this.company_description,
company_logo_url: this.company_logo_url
};
}, Job.prototype.get_years_experience_min_display = function() {
return -1 === this.years_experience_min ? 0 : this.years_experience_min;
}, Job.prototype.get_years_experience_max_display = function() {
return -1 === this.years_experience_max ? "20+" : this.years_experience_max;
},
// This is actally what gets returned (note the `return` and commas above):
Job;
}();
},
// Give the JonModel to Angular:
angular.module("App").factory("JobModel", JobModel);
}();
// Encapsulate all of this to protect global namespace (inject `this`)
}.call(this), function() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment