Posty

Wyświetlanie postów z 2017

Interesting uses of IDisposable

Everyone knows IDisposable interface, right? Right. It is simple. If you use unmanaged resources, you should implement IDisposable and release them when your object is being disposed. Simple. But IDisposable is a very special interface. It even has its own keyword: using. Example use:Code above is equal to:Constructor is called first, then we are doing something inside, and at the end Dispose method is called to finalize work. So maybe we could use IDisposable not only to clean up unmanaged resources, but as a shorter form of try / finally to put our code in specific context. That sounds like a great idea and obviously it is not mine. This idea was used in few places in .NET libraries. Here are 4 examples of IDisposable:First example. This is code from ASP.NET MVC to generate HTML form using Razor:Output of this code will be close to:What happens? Html.BeginForm() is a function that writes "<form>" to response and returns MvcForm type object. MvcForm type implements ID…

Angular 2 and AOT (ahead of time) compilation

Obraz
Today I managed to run AOT compilation in existing Angular 2 application.This is a note to remember what I had to do to make it work:Follow this example: https://medium.com/@laco0416/aot-compilation-with-webpack-359ac9f4916f#.a1v35vlylDowngrade Typescript to 2.0.10.Downgrade Webpack to 2.1.0-beta.28.Change all "template: require(path)" to "templateUrl: path". Require function is not available in AOT compilation process.Had to add angular2-typescript-loader to handle ts files in webpack (loaders: isProd ? '@ngtools/webpack' : ["awesome-typescript-loader", 'angular2-template-loader']). It handles templateUrl in components.Newest versions of libraries (ts 2.2 and webpack 2.2.0-rc.3) had documented issues with whole mechanism, so I had some fun searching for solutions.Performance before enabling AOT compilation: And after
Scripting took 3 seconds less and it is more than visible. Difference is huge. Scripts are now 600KB bigger, but they load on…