Thursday, April 7, 2016

Javascript: the module pattern

The module pattern is defined by two things.

1-An outter wrapping function

2-An returned object containing at least one function

It was initially introduced a decade ago by Douglas Crockford in order to provide encapsulation, therefore exposing only what is needed, reducing the risk users would access, undocumented features.  

Javascript: Closure

       Closure is the capability to remember it's lexical scope, even when executed outside it's lexical scope.

If two inner functions, are within the same scope, they share the same closure.    

Wednesday, April 6, 2016

Javascript: The 'this' keyword



Here is a summary of the 4 rules defining the value of 'this':

1-Was the function called with the new keyword? If so, use that object.
2-Was the function called explicitly with call or apply? Use the passed in object.
3-Was the function called implicitly with the dot operator? Use the owning object, also called base object or context object, which means the object to the left of the dot of the function invocation.

4-If none of the above, the default rule applies, 'this' is the global object, except if in strict mode, 'this' is set to undefined.    

Javascript: It`s misunderstood concepts

Javascript gained in popularity in the last decade following Google`s V8 engine then client side frameworks like AngularJs and server side development in NodeJs.

According to StackOverflow`s 2015 survey, Javascript is the most used programming language. Yet many still compare using this language to dancing in the minefield.

Javascript does have many concepts that are often misunderstood. For example the `this` keyword, doesn't behave the same as in C, C++, or Java. Coming from these language means almost forgetting anything we know about 'this' when learning how 'this' behaves in Javascript.

Other misunderstood concepts of Javascript are: Scope, proto chains, hoisting and closures.

I will summarize some of these key concepts in the following blog posts.

Sunday, September 19, 2010

70-562 Dynamic Data

Object Relational Mappers, for example Linq and Entity Framework are well integrated in VS 2008, and have project template available; Dynamic Data Web Site.

Creating a dynamic data web site project is a good way to explore the server controls and datasources offered via the toolbox menu.

This template starts out witha basic website shell, but the connection string isnt configured. The Linq to SQL and Entity to SQL are the ORM offered and by default use the default databse located in App_Data folder of this template project.

The designer.cs file defines the data model and wraps the objects around it in order to access the data model via code.

In the global.asax contains the RegisterRoutes method that comes with a default model.RegisterContext method of the type YourDataConectType, you will replace this one with your data context which, after having created the model pointing to your database should be avaialble in intellisence under the name yourDatabaseNameDataContext.
ScaffoldAllTables to true will include all the tables in the model.

At th8is point it's possible to run the website and default.aspx that will show the various tables in your model and page the content of each table when clicking on the table.

If you notice the form of the URL, this can be customized through routing in the global.asax file, using the ASP.Net routing engine.

In this site, there is no code generation, the sturction is based on templates and is dynamic thanks to routing features that reuse the same edit.aspx page for each item.

For example this routing defintion is defuined by routes.Add(new DynamicRoute("{Table}/{actions}.aspx"));

There is a lot to say on ORMs and Dynamic Data layers, the purpose of this section was mostly to summarize some of the VS2008 features that make using Linq and EF faster and customizable.

70-562 Security Trimming

Security Triming is achieved by putting a web.config in each folder... each aspx file has its own folder denies * all users, and db tables in the app_data folder can be maintained with the website administration tool
wwebadmin tool can be started from website->configuration then you click on the security link, then manage users so there's two layers of security, the ones in the app_data folder and the ones in web.config that overide
app_data.

Web adminstration tool can use both both form and windows authentication, windows is handled by iis there is a control for the login button, and one to display the login user user in the sitemap section of the web.config needs to say securityTrimming enabled if a node doesnt have a page associated with it, the node needs to have roles attribute to allow to access to any pages in it's subfolder, or is this just to show the menu item in the sitepath control?

Giving roles to a sitemap node just show the node doesnt give access to the page, this is done in the child web.config files

70-562 Navigation API


You can add custom attributes for each node in the xml file, like the sound and image of an animal to set to label and img you can check if there is a previous sibling to add a previous button(set the button to visible, do all this in page_load in general when testing new features, you can add a checkbox to display info to make sure you can read it, even it's if its irrevelant for the user to see, you just add labels at the bottom of the page, and you can even add this in the master page as a footer, you could put all this in the server div control and use innerHTML property you can use it for rewriting(rerouting) urls so they dont include query string, in the web.config in urlMappings element. Might want to put these mappings in an external .config (set the configSource attrtibute of the urlMappings elementconfiguration file, external config change doesnt cause an application restart.

Setting the url in the sitemap file also allows to remap urls sitemap files to have child sitemap files.