Skip to content

Instantly share code, notes, and snippets.

@mrmccormack
Last active April 10, 2018 12:17
Show Gist options
  • Save mrmccormack/0db6560406df50906f9c50c6ccf15c2a to your computer and use it in GitHub Desktop.
Save mrmccormack/0db6560406df50906f9c50c6ccf15c2a to your computer and use it in GitHub Desktop.
Example using JavaScript Standard formatting

Understanding "JavaScript Standard" format

  • The code shown here: refreshcomposite.js is how you might be writing JavaScript
  • Let's try to format this up using the "JavaScript Standard" - which is gaining in popularite

Movie of the Week


NOTE:

  • some programmers hate the JavaScript standard, others love it -
  • Best advice, use whatever style / standard / best practices your boss wants you to use

Tasks

  1. Copy the refreshcomposite.js code to your clipboard
  2. Go to: https://standardjs.com/demo.html
  3. Paste in the code
  4. Note carefully - all the suggestions that will make this code follow the standard
  5. Press the button to format it
  6. Inspect it carefully - What to you think

#TIPS All good editors (Atom.io, SublimeText etc.) have:

  1. something called auto formatters, which will do this for you right in your editor
  2. something called Linters - this will let you know of any errors as you are typing

Watch a demo to see some of this in action:


const {RefreshComposite, CheckBox, ScrollView, TextView, ui} = require('tabris');
const counter = 0 ;
var First_Name = "bob";
let refreshComposite = new RefreshComposite({
left: 0, right: 0, top: 0, bottom: 0,
}).on('refresh', ({target}) => setTimeout(() => {
target.refreshIndicator = false;
textView.text = `last refresh: ${new Date()}\n${textView.text}`;
}, 1000)).appendTo(ui.contentView);
let scrollView = new ScrollView({
left: 0, right: 0, top: 0, bottom: 0,
}).appendTo(refreshComposite);
new TextView({
left: 0, right: 0, top: 32,
alignment: 'center',
font: 'black 24px',
text: 'pull to refresh'
}).appendTo(scrollView);
const textView = new TextView({
left: 0, right: 0, top: 'prev() 32',
alignment: 'center',
lineSpacing: 1.4,
}).appendTo(scrollView);
new CheckBox({
left: 16, right: 16, bottom: 16,
text: 'Enable pull to refresh',
checked: true
}).on('checkedChanged', ({value: checked}) => refreshComposite.refreshEnabled = checked)
.appendTo(ui.contentView);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment