Skip to content

Latest commit

 

History

History
47 lines (32 loc) · 1.15 KB

change-detection.md

File metadata and controls

47 lines (32 loc) · 1.15 KB

Change detection

Change detection in slicky is really easy, since there is only one rule you need to remember - use only immutable variables.

The best and easies way to work with immutable types is with immutable.js library. You can look at an example todo app.

Components

Change detection for components is always fired after any life cycle event and any asynchronous call inside of them (ajax, timeout, interval etc.).

Sometimes however the call can not be detected automatically. Luckily you can tell slicky to check for changes manually.

import {Component, OnInit, ChangeDetectorRef} from '@slicky/core';

@Component({
	name: 'my-component',
	template: 'count: {{ count }}',
})
class MyComponent implements OnInit
{
	
	
	public count = 0;
	
	private changeDetector: ChangeDetectorRef;
	
	
	constructor(changeDetector: ChangeDetectorRef)
	{
		this.changeDetector = changeDetector;
	}
	
	
	public onInit(): void
	{
		someUndetectableAsyncCall(() => {
			this.count++;
			this.changeDetector.refresh();
		});
	}
	
}