Show:

{ajax_interface} Class

Module: breeze

This is an interface description. Any class that implements the methods and properties defined here is considered a valid implementation of this interface.

Methods

ajax

(
  • config
)

Performs an ajax request. This method takes a single argument — a configuration object — that is used to generate an HTTP request. The config object has two callback methods: 'success' and 'error' in addition to a number of properties that may be used to configure the request itself. Higher level Breeze constructs will wrap calls to the ajax adapter into Promises. Individual adapters may add additional properties to the basic config object described below.

Parameters:

  • config Object
    • url String

      Absolute or relative URL of the resource that is being requested.

    • type String

      HTTP method (e.g. 'GET', 'POST', etc)

    • [data] Object | String optional

      Data to be sent as the request message data

    • [params] optional

      Map of strings or objects which will be sent to the server in the query string in a form encoded format - url?key1=value1&key2=value2

    • [crossDomain=false] optional
    • success Function

      Function called on success. successFunction(httpResponse)

    • error Function

      Function called on failure. errorFunction(httpResponse)

changeRequestInterceptor

(
  • saveContext
  • saveBundle
)
Function

Returns a constructor function for a "ChangeRequestInterceptor" that can tweak the saveBundle both as it is built and when it is completed by a concrete DataServiceAdapater.

Initialized with a default, no-op implementation that developers can replace with a substantive implementation that changes the individual entity change requests or aspects of the entire 'saveBundle' without having to write their own DataService adapters.

Parameters:

  • saveContext Object

    The BreezeJS "context" for the save operation.

  • saveBundle Object

    Contains the array of entities-to-be-saved (AKA, the entity change-set).

Returns:

Function:

Constructor for a "ChangeRequestInterceptor".

Example:

var adapter = breeze.config.getAdapterInstance('dataService'); adapter.changeRequestInterceptor = function (saveContext, saveBundle) { this.getRequest = function (request, entity, index) { // alter the request that the adapter prepared for this entity // based on the entity, saveContext, and saveBundle // e.g., add a custom header or prune the originalValuesMap return request; }; this.done = function (requests) { // alter the array of requests representing the entire change-set // based on the saveContext and saveBundle }; }

done

(
  • requests
)

Last chance to change anything about the 'requests' array after it has been built with requests for all of the entities-to-be-saved.

The 'requests' array is the same as 'saveBundle.entities' in many implementations

This method can do anything to the array including add and remove requests. It's up to you to ensure that server will accept the requests array data as valid.

Returned value is ignored.

Parameters:

  • requests Array of Object

    The adapter's array of request for this changeset.

Example:

this.done = function (requests) { // alter the array of requests representing the entire change-set // based on the saveContext and saveBundle };

getRequest

(
  • request
  • entity
  • index
)
Function

Prepare and return the save data for an entity change-set.

The adapter calls this method for each entity in the change-set, after it has prepared a "change request" for that object.

The method can do anything to the request but it must return a valid, non-null request.

Parameters:

  • request Object

    The object representing the adapter's request to save this entity.

  • entity Entity

    The entity-to-be-save as it is in cache

  • index Integer

    The zero-based index of this entity in the change-set array

Returns:

Function:

The potentially revised request.

Example:

this.getRequest = function (request, entity, index) { // alter the request that the adapter prepared for this entity // based on the entity, saveContext, and saveBundle // e.g., add a custom header or prune the originalValuesMap return request; };