Ajax & Jasmine Flashcards

1
Q

What is the process of an Ajax Call?

A

Split transaction. You send something to server. Server responds. Triggers Event. Then you can run code based on that event.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are events?

A

Typical user events like moving the mouse, etc. Then you can bind your javascript objects using JQuery to a certain event.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you ensure that javascript will work on a browser?

A

You put your javascript functions in a setup code so that it can only run once javascript is setup and will not run if they do not have javascript.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Steps to Manipulate the DOM using events.

A

Identify elements you wins to work on.
Identify elements that interactions will trigger stuff to happen
Create failing tests for handler with TDD
Write Handler functions that cause desired act
In a setup function, bind the handlers.

Make sure you call $(variable.setup)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What happens to links or buttons that are clickable without javascript?

A
  • handler runs first
  • if handler returns false or no action taken
  • otherwise other actions follow handler
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Ajax?

A

JSAPI call XmlHttpRequest contacts server asynchronously (in background) and without redrawing the page. We can use the information from the server anyway we want.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

A controller action receives request via route what should it render if the request is an Ajax call?

A
You can render a lot of different things.
render :layout => false
render :partial => 'movies/show'
render :json => @movies
render :xml => @movies
render :text => @movie.title
render :nothing => true
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
Keys to Ajax Calls:
Réponse Content Type?
Controller Actions?
Server rely on?
Will it Freeze the UI?
A

Response Content type can be anything, not just HTML
Ajax can be handled with its own controller actions
Server must rely on an explicit hint
It won’t freeze the UI if server fails to respond?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are True of Jasmine’s it() method?
It can take a named function as its second argument.
It can take an anonymous function as its 2nd argument
it executes asynchronously.

A

It can take a names function as its 2nd argument

It can take an anonymous function as its 2 argument.

It does not execute asynchronously.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are stubs in Jasmine?

A

They are called spies. They shadow the method and they basically replaces the method. Stub out the place you want to call and then give it the values it should return.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What about Fixtures in Jasmine?

A

Just enough html for your function to be able to run in its environment. You call load fixtures(‘name.html’) and then it will load it into div#jasmine-fixtures

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What about Stubbing Ajax?

A

Remember that Ajax then calls another function. The success function gets called in Ajax if the call goes through so to spy on Ajax you have to use
spyOn($, ‘ajax’).andCallFake(function(ajaxArgs) {
ajaxArgs.success(htmlResponse, ‘200’);
});

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Does Ajax Return Server reply content?

A

No it does not. So in stubbing, andReturn won’t work.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

My Ajax calls are slow, can I assume that it is the server?

A

No it could be slow interpreter, could be slow database, could be network delays because too much data to browser.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Why would you want to minify javascript?

A

Fast page load times

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is true about prototype?

i. It can be used to mimic class inheritance.
ii. If property doesn’t exist it checks the prototype chain.
iii. Every object inherits from exactly one prototype object
iv. Null is returned when we reach top of prototype chain and no property has been found.

A

i and ii.

17
Q
Explain the Different Design Patterns:
Observer
Strategy
Factory
Abstract
Singleton
Prototype
A
Abstract Factory: Creates an instance of several families of classes
Builder: Separates object construction from its representation
Factory Method: Creates an instance of several derived classes
Object Pool: Avoid expensive acquisition and release of resources by recycling objects that are no longer in use
Prototype: A fully initialized instance to be copied or cloned
Singleton: A class of which only a single instance can exist
Bridge: Separates an object’s interface from its implementation
Observer: A way of notifying change to a number of classes