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 JSBin to Tips #372

Open
wants to merge 5 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions _posts/en/angular/2016-01-01-angularjs-digest-vs-apply.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: post

title: AngularJs - `$digest` vs `$apply`
tip-number: 01
tip-username: loverajoel
tip-username: loverajoel
tip-username-profile: https://github.com/loverajoel
tip-tldr: JavaScript modules and build steps are getting more numerous and complicated, but what about boilerplate in new frameworks?
tip-writer-support: https://www.coinbase.com/loverajoel
Expand Down Expand Up @@ -40,4 +40,9 @@ $scope.$apply(() => {

- If you only need to update the current scope or its children, use `$digest`, and prevent a new digest cycle for the whole application. The performance benefit is self-evident.
- `$apply()` is a hard process for the machine and can lead to performance issues when there is a lot of binding.
- If you are using >AngularJS 1.2.X, use `$evalAsync`, which is a core method that will evaluate the expression during the current cycle or the next. This can improve your application's performance
- If you are using >AngularJS 1.2.X, use `$evalAsync`, which is a core method that will evaluate the expression during the current cycle or the next. This can improve your application's performance.

## Playground
<div>
Not available due to the nature of the tip.
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,9 @@ var items = ['one', 'two', 'three', 'four'];
items.splice(items.length / 2, 0, 'hello');
```

I tried to run these tests in various Browsers and OS and the results were similar. I hope these tips will be useful for you and encourage to perform your own tests!
I tried to run these tests in various Browsers and OS and the results were similar. I hope these tips will be useful for you and encourage to perform your own tests!

## Playground
<div>
<a class="jsbin-embed" href="http://jsbin.com/xeqeya/embed?js,console">JS Bin on jsbin.com</a><script src="http://static.jsbin.com/js/embed.min.js?3.39.12"></script>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: post

title: Improve Nested Conditionals
tip-number: 03
tip-username: AlbertoFuente
tip-username: AlbertoFuente
tip-username-profile: https://github.com/AlbertoFuente
tip-tldr: How can we improve and make a more efficient nested `if` statement in javascript?

Expand Down Expand Up @@ -104,3 +104,6 @@ if (color in colorObj) {
```

Here you can find more information about [this](http://www.nicoespeon.com/en/2015/01/oop-revisited-switch-in-js/).

## Playground
<a class="jsbin-embed" href="https://jsbin.com/vubeno/embed?js,console">JS Bin on jsbin.com</a><script src="https://static.jsbin.com/js/embed.min.js?3.39.12"></script>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: post

title: Sorting strings with accented characters
tip-number: 04
tip-username: loverajoel
tip-username: loverajoel
tip-username-profile: https://github.com/loverajoel
tip-tldr: Javascript has a native method **sort** that allows sorting arrays. Doing a simple `array.sort()` will treat each array entry as a string and sort it alphabetically. But when you try order an array of non ASCII characters you will obtain a strange result.
tip-writer-support: https://www.coinbase.com/loverajoel
Expand Down Expand Up @@ -68,4 +68,9 @@ Fortunately, there are two ways to overcome this behavior [localeCompare](https:
- For each method you can customize the location.
- According to [Firefox](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#Performance) Intl.Collator is faster when comparing large numbers of strings.

So when you are working with arrays of strings in a language other than English, remember to use this method to avoid unexpected sorting.
So when you are working with arrays of strings in a language other than English, remember to use this method to avoid unexpected sorting.

## Playground
<div>
<a class="jsbin-embed" href="https://jsbin.com/bazume/embed?js,console">JSTips.co - Sorting strings with accented characters on jsbin.com</a><script src="https://static.jsbin.com/js/embed.min.js?3.39.12"></script>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: post

title: Keys in children components are important
tip-number: 02
tip-username: loverajoel
tip-username: loverajoel
tip-username-profile: https://github.com/loverajoel
tip-tldr: The key is an attribute that you must pass to all components created dynamically from an array. It's a unique and constant id that React uses to identify each component in the DOM and to know whether it's a different component or the same one. Using keys ensures that the child component is preserved and not recreated and prevents weird things from happening.
tip-writer-support: https://www.coinbase.com/loverajoel
Expand Down Expand Up @@ -44,4 +44,9 @@ render() {

- You can create your own unique id. Be sure that the method is fast and attach it to your object.
- When the number of children is large or contains expensive components, use keys to improve performance.
- [You must provide the key attribute for all children of ReactCSSTransitionGroup.](http://docs.reactjs-china.com/react/docs/animation.html)
- [You must provide the key attribute for all children of ReactCSSTransitionGroup.](http://docs.reactjs-china.com/react/docs/animation.html)

## Playground
<div>
Not available due to the nature of the tip.
</div>