Gusto Engineering

Reengineering Payroll, Benefits, and HR for modern business. Hiring empathetic engineers in San Francisco, Denver and NYC! https://gusto.com/about/careers

Follow publication

Evolving JavaScript Part 1

Nikhil Mathew
Gusto Engineering
Published in
6 min readJul 12, 2016

--

Why Our Stack Used to Make Sense

Breaking Up with Backbone

Non-Trivial Composability

class ShowView extends Backbone.View  
template: HandlebarsTemplates['employees/show']
className: 'employee-show-view'
initialize: (options) ->
@company = options.company
... appendSection: (viewClass, options) ->
view = new viewClass(_(model: @model).extend(options))
@registerSubView(view)
@$('#employee-sections').append(view.render().el)
view
render: ->
@tearDownSubViews()
@$el.html(@template(employee: @model.toJSON()))
@appendSection(AddressesView)
@appendSection(SplittableShowView)
@appendSection(CompensationsView, company: @company)
@appendSection(FederalTaxesView)
@appendSection(SpecialExemptionView, company: @company)
@appendStateTaxViews()
@appendDismissView()
@appendRehireView()
@appendFormsView()
@appendPaystubView()

Events Triggering Manual DOM Updates

class PaymentDetailsFormView extends Backbone.View  
template: HandlebarsTemplates['contractors/payment_details_form']
className: 'contractor-payment-details-form-view'
events:
'change .payment-method': 'updatePaymentMethod'
'keyup .routing-field': 'updateBankName'
initialize: (options) ->
@company = options.company
... updatePaymentMethod: ->
paymentMethod = @$('.payment-method').val()
if paymentMethod is ENVIRONMENT.PAYMENT_METHOD_CHECK
@$('#pay-by-check').removeClass('hide')
@$('#pay-by-direct-deposit').addClass('hide')
else if paymentMethod is ENVIRONMENT.PAYMENT_METHOD_DIRECT_DEPOSIT
@$('#pay-by-check').addClass('hide')
@$('#pay-by-direct-deposit').removeClass('hide')
else
@$('#pay-by-direct-deposit, #pay-by-check').addClass('hide')
updateBankName: ->
routingNumber = @$('.routing-field').val().replace(/_+/, '')
if routingNumber.length == 9
$.ajax(
type: 'GET'
url: API_PREFIX + '/banks/' + routingNumber
).done((response) =>
if response['name']?
@$('#bank-lookup-name p').text(response['name'])
@$('#bank-lookup-name p').addClass('name-shown')
else
@$('#bank-lookup-name p').text('')
@$('#bank-lookup-name p').removeClass('name-shown')
)
else
@$('#bank-lookup-name p').text('')
@$('#bank-lookup-name p').removeClass('name-shown')

Inefficient DOM Manipulation

class NavView extends Backbone.View  
className: 'nav-menu'
initialize: (options) ->
@user = options.user
@company = options.company
@listenTo(@company.companyMigration, 'change', @render) ...

So, what do we do?

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Published in Gusto Engineering

Reengineering Payroll, Benefits, and HR for modern business. Hiring empathetic engineers in San Francisco, Denver and NYC! https://gusto.com/about/careers

No responses yet

Write a response