Input: Selects the best location option based off browser support and returns an instance of that Location class . [CODESPLIT] function ( options ) { if ( options && options . rootURL ) { Ember . assert ( 'rootURL must end with a trailing forward slash e.g. "/app/"' , options . rootURL . charAt ( options . rootURL . length - 1 ) === '/' ) ; this . rootURL = options . rootURL ; } var historyPath , hashPath , cancelRouterSetup = false , implementationClass = this . _NoneLocation , currentPath = this . _getFullPath ( ) ; if ( this . _getSupportsHistory ( ) ) { historyPath = this . _getHistoryPath ( ) ; // Since we support history paths, let's be sure we're using them else // switch the location over to it. if ( currentPath === historyPath ) { implementationClass = this . _HistoryLocation ; } else { cancelRouterSetup = true ; this . _replacePath ( historyPath ) ; } } else if ( this . _getSupportsHashChange ( ) ) { hashPath = this . _getHashPath ( ) ; // Be sure we're using a hashed path, otherwise let's switch over it to so // we start off clean and consistent. We'll count an index path with no // hash as "good enough" as well. if ( currentPath === hashPath || ( currentPath === '/' && hashPath === '/#/' ) ) { implementationClass = this . _HashLocation ; } else { // Our URL isn't in the expected hash-supported format, so we want to // cancel the router setup and replace the URL to start off clean cancelRouterSetup = true ; this . _replacePath ( hashPath ) ; } } var implementation = implementationClass . create . apply ( implementationClass , arguments ) ; if ( cancelRouterSetup ) { set ( implementation , 'cancelRouterSetup' , true ) ; } return implementation ; }


Input: This method is called via the container s resolver method . It parses the provided fullName and then looks up and returns the appropriate template or class . [CODESPLIT] function ( fullName ) { var parsedName = this . parseName ( fullName ) , resolveMethodName = parsedName . resolveMethodName ; if ( ! ( parsedName . name && parsedName . type ) ) { throw new TypeError ( "Invalid fullName: `" + fullName + "`, must be of the form `type:name` " ) ; } if ( this [ resolveMethodName ] ) { var resolved = this [ resolveMethodName ] ( parsedName ) ; if ( resolved ) { return resolved ; } } return this . resolveOther ( parsedName ) ; }


Input: Convert the string name of the form type : name to a Javascript object with the parsed aspects of the name broken out . [CODESPLIT] function ( fullName ) { var nameParts = fullName . split ( ":" ) , type = nameParts [ 0 ] , fullNameWithoutType = nameParts [ 1 ] , name = fullNameWithoutType , namespace = get ( this , 'namespace' ) , root = namespace ; if ( type !== 'template' && name . indexOf ( '/' ) !== - 1 ) { var parts = name . split ( '/' ) ; name = parts [ parts . length - 1 ] ; var namespaceName = capitalize ( parts . slice ( 0 , - 1 ) . join ( '.' ) ) ; root = Ember . Namespace . byName ( namespaceName ) ; Ember . assert ( 'You are looking for a ' + name + ' ' + type + ' in the ' + namespaceName + ' namespace, but the namespace could not be found' , root ) ; } return { fullName : fullName , type : type , fullNameWithoutType : fullNameWithoutType , name : name , root : root , resolveMethodName : "resolve" + classify ( type ) } ; }


Input: Look up the template in Ember . TEMPLATES [CODESPLIT] function ( parsedName ) { var templateName = parsedName . fullNameWithoutType . replace ( / \. / g , '/' ) ; if ( Ember . TEMPLATES [ templateName ] ) { return Ember . TEMPLATES [ templateName ] ; } templateName = decamelize ( templateName ) ; if ( Ember . TEMPLATES [ templateName ] ) { return Ember . TEMPLATES [ templateName ] ; } }


Input: If the application has not opted out of routing and has not explicitly defined a router supply a default router for the application author to configure . [CODESPLIT] function ( ) { if ( this . Router === false ) { return ; } var container = this . __container__ ; if ( this . Router ) { container . unregister ( 'router:main' ) ; container . register ( 'router:main' , this . Router ) ; } return container . lookupFactory ( 'router:main' ) ; }


Input: Automatically initialize the application once the DOM has become ready . [CODESPLIT] function ( ) { var self = this ; if ( ! this . $ || this . $ . isReady ) { Ember . run . schedule ( 'actions' , self , '_initialize' ) ; } else { this . $ ( ) . ready ( function runInitialize ( ) { Ember . run ( self , '_initialize' ) ; } ) ; } }


Input: Call advanceReadiness after any asynchronous setup logic has completed . Each call to deferReadiness must be matched by a call to advanceReadiness or the application will never become ready and routing will not begin . [CODESPLIT] function ( ) { Ember . assert ( "You must call advanceReadiness on an instance of Ember.Application" , this instanceof Ember . Application ) ; this . _readinessDeferrals -- ; if ( this . _readinessDeferrals === 0 ) { Ember . run . once ( this , this . didBecomeReady ) ; } }


Input: Reset the application . This is typically used only in tests . It cleans up the application in the following order : [CODESPLIT] function ( ) { this . _readinessDeferrals = 1 ; function handleReset ( ) { var router = this . __container__ . lookup ( 'router:main' ) ; router . reset ( ) ; Ember . run ( this . __container__ , 'destroy' ) ; this . buildContainer ( ) ; Ember . run . schedule ( 'actions' , this , function ( ) { this . _initialize ( ) ; } ) ; } Ember . run . join ( this , handleReset ) ; }


Input: Setup up the event dispatcher to receive events on the application s rootElement with any registered customEvents . [CODESPLIT] function ( ) { var customEvents = get ( this , 'customEvents' ) , rootElement = get ( this , 'rootElement' ) , dispatcher = this . __container__ . lookup ( 'event_dispatcher:main' ) ; set ( this , 'eventDispatcher' , dispatcher ) ; dispatcher . setup ( customEvents , rootElement ) ; }


Input: This creates a container with the default Ember naming conventions . [CODESPLIT] function ( namespace ) { var container = new Ember . Container ( ) ; Ember . Container . defaultContainer = new DeprecatedContainer ( container ) ; container . set = Ember . set ; container . resolver = resolverFor ( namespace ) ; container . normalize = container . resolver . normalize ; container . describe = container . resolver . describe ; container . makeToString = container . resolver . makeToString ; container . optionsForType ( 'component' , { singleton : false } ) ; container . optionsForType ( 'view' , { singleton : false } ) ; container . optionsForType ( 'template' , { instantiate : false } ) ; container . optionsForType ( 'helper' , { instantiate : false } ) ; container . register ( 'application:main' , namespace , { instantiate : false } ) ; container . register ( 'controller:basic' , Ember . Controller , { instantiate : false } ) ; container . register ( 'controller:object' , Ember . ObjectController , { instantiate : false } ) ; container . register ( 'controller:array' , Ember . ArrayController , { instantiate : false } ) ; container . register ( 'route:basic' , Ember . Route , { instantiate : false } ) ; container . register ( 'event_dispatcher:main' , Ember . EventDispatcher ) ; container . register ( 'router:main' , Ember . Router ) ; container . injection ( 'router:main' , 'namespace' , 'application:main' ) ; container . register ( 'location:auto' , Ember . AutoLocation ) ; container . register ( 'location:hash' , Ember . HashLocation ) ; container . register ( 'location:history' , Ember . HistoryLocation ) ; container . register ( 'location:none' , Ember . NoneLocation ) ; container . injection ( 'controller' , 'target' , 'router:main' ) ; container . injection ( 'controller' , 'namespace' , 'application:main' ) ; container . injection ( 'route' , 'router' , 'router:main' ) ; container . injection ( 'location' , 'rootURL' , '-location-setting:root-url' ) ; // DEBUGGING container . register ( 'resolver-for-debugging:main' , container . resolver . __resolver__ , { instantiate : false } ) ; container . injection ( 'container-debug-adapter:main' , 'resolver' , 'resolver-for-debugging:main' ) ; container . injection ( 'data-adapter:main' , 'containerDebugAdapter' , 'container-debug-adapter:main' ) ; // Custom resolver authors may want to register their own ContainerDebugAdapter with this key container . register ( 'container-debug-adapter:main' , Ember . ContainerDebugAdapter ) ; return container ; }


Input: Fetch the records of a given type and observe them for changes . [CODESPLIT] function ( type , recordsAdded , recordsUpdated , recordsRemoved ) { var self = this , releaseMethods = Ember . A ( ) , records = this . getRecords ( type ) , release ; var recordUpdated = function ( updatedRecord ) { recordsUpdated ( [ updatedRecord ] ) ; } ; var recordsToSend = records . map ( function ( record ) { releaseMethods . push ( self . observeRecord ( record , recordUpdated ) ) ; return self . wrapRecord ( record ) ; } ) ; var contentDidChange = function ( array , idx , removedCount , addedCount ) { for ( var i = idx ; i < idx + addedCount ; i ++ ) { var record = array . objectAt ( i ) ; var wrapped = self . wrapRecord ( record ) ; releaseMethods . push ( self . observeRecord ( record , recordUpdated ) ) ; recordsAdded ( [ wrapped ] ) ; } if ( removedCount ) { recordsRemoved ( idx , removedCount ) ; } } ; var observer = { didChange : contentDidChange , willChange : Ember . K } ; records . addArrayObserver ( self , observer ) ; release = function ( ) { releaseMethods . forEach ( function ( fn ) { fn ( ) ; } ) ; records . removeArrayObserver ( self , observer ) ; self . releaseMethods . removeObject ( release ) ; } ; recordsAdded ( recordsToSend ) ; this . releaseMethods . pushObject ( release ) ; return release ; }


Input: Adds observers to a model type class . [CODESPLIT] function ( type , typesUpdated ) { var self = this , records = this . getRecords ( type ) ; var onChange = function ( ) { typesUpdated ( [ self . wrapModelType ( type ) ] ) ; } ; var observer = { didChange : function ( ) { Ember . run . scheduleOnce ( 'actions' , this , onChange ) ; } , willChange : Ember . K } ; records . addArrayObserver ( this , observer ) ; var release = function ( ) { records . removeArrayObserver ( self , observer ) ; } ; return release ; }


Input: Loops over all namespaces and all objects attached to them [CODESPLIT] function ( ) { var namespaces = Ember . A ( Ember . Namespace . NAMESPACES ) , types = Ember . A ( ) ; namespaces . forEach ( function ( namespace ) { for ( var key in namespace ) { if ( ! namespace . hasOwnProperty ( key ) ) { continue ; } var name = Ember . String . dasherize ( key ) ; if ( ! ( namespace instanceof Ember . Application ) && namespace . toString ( ) ) { name = namespace + '/' + name ; } types . push ( name ) ; } } ) ; return types ; }


Input: This allows ember - testing to play nicely with other asynchronous events such as an application that is waiting for a CSS3 transition or an IndexDB transaction . [CODESPLIT] function ( context , callback ) { if ( arguments . length === 1 ) { callback = context ; context = null ; } if ( ! this . waiters ) { this . waiters = Ember . A ( ) ; } this . waiters . push ( [ context , callback ] ) ; }


Input: unregisterWaiter is used to unregister a callback that was registered with registerWaiter . [CODESPLIT] function ( context , callback ) { var pair ; if ( ! this . waiters ) { return ; } if ( arguments . length === 1 ) { callback = context ; context = null ; } pair = [ context , callback ] ; this . waiters = Ember . A ( this . waiters . filter ( function ( elt ) { return Ember . compare ( elt , pair ) !== 0 ; } ) ) ; }


Input: This injects the test helpers into the helperContainer object . If an object is provided it will be used as the helperContainer . If helperContainer is not set it will default to window . If a function of the same name has already been defined it will be cached ( so that it can be reset if the helper is removed with unregisterHelper or removeTestHelpers ) . [CODESPLIT] function ( helperContainer ) { if ( helperContainer ) { this . helperContainer = helperContainer ; } this . testHelpers = { } ; for ( var name in helpers ) { this . originalMethods [ name ] = this . helperContainer [ name ] ; this . testHelpers [ name ] = this . helperContainer [ name ] = helper ( this , name ) ; protoWrap ( Ember . Test . Promise . prototype , name , helper ( this , name ) , helpers [ name ] . meta . wait ) ; } for ( var i = 0 , l = injectHelpersCallbacks . length ; i < l ; i ++ ) { injectHelpersCallbacks [ i ] ( this ) ; } }


Input: This removes all helpers that have been registered and resets and functions that were overridden by the helpers . [CODESPLIT] function ( ) { for ( var name in helpers ) { this . helperContainer [ name ] = this . originalMethods [ name ] ; delete this . testHelpers [ name ] ; delete this . originalMethods [ name ] ; } }


Input: This method is no longer needed But still here for backwards compatibility of helper chaining [CODESPLIT] function protoWrap ( proto , name , callback , isAsync ) { proto [ name ] = function ( ) { var args = arguments ; if ( isAsync ) { return callback . apply ( this , args ) ; } else { return this . then ( function ( ) { return callback . apply ( this , args ) ; } ) ; } } ; }


Input: returns the log array [CODESPLIT] function cleanerEval ( str , oldConsole ) { var logArr = [ ] ; var console = { log : function ( msg ) { logArr . push ( msg ) ; oldConsole . log ( msg ) ; } } ; eval ( str ) ; return logArr ; }


Input: Adapted from ES5 section 8 . 10 . 5 [CODESPLIT] function toPropertyDescriptor ( obj ) { if ( Object ( obj ) !== obj ) { throw new TypeError ( "property descriptor should be an Object, given: " + obj ) ; } var desc = { } ; if ( 'enumerable' in obj ) { desc . enumerable = ! ! obj . enumerable ; } if ( 'configurable' in obj ) { desc . configurable = ! ! obj . configurable ; } if ( 'value' in obj ) { desc . value = obj . value ; } if ( 'writable' in obj ) { desc . writable = ! ! obj . writable ; } if ( 'get' in obj ) { var getter = obj . get ; if ( getter !== undefined && typeof getter !== "function" ) { throw new TypeError ( "property descriptor 'get' attribute must be " + "callable or undefined, given: " + getter ) ; } desc . get = getter ; } if ( 'set' in obj ) { var setter = obj . set ; if ( setter !== undefined && typeof setter !== "function" ) { throw new TypeError ( "property descriptor 'set' attribute must be " + "callable or undefined, given: " + setter ) ; } desc . set = setter ; } if ( 'get' in desc || 'set' in desc ) { if ( 'value' in desc || 'writable' in desc ) { throw new TypeError ( "property descriptor cannot be both a data and an " + "accessor descriptor: " + obj ) ; } } return desc ; }


Input: Returns a fresh property descriptor that is guaranteed to be complete ( i . e . contain all the standard attributes ) . Additionally any non - standard enumerable properties of attributes are copied over to the fresh descriptor . [CODESPLIT] function normalizeAndCompletePropertyDescriptor ( attributes ) { if ( attributes === undefined ) { return undefined ; } var desc = toCompletePropertyDescriptor ( attributes ) ; // Note: no need to call FromPropertyDescriptor(desc), as we represent // "internal" property descriptors as proper Objects from the start for ( var name in attributes ) { if ( ! isStandardAttribute ( name ) ) { Object . defineProperty ( desc , name , { value : attributes [ name ] , writable : true , enumerable : true , configurable : true } ) ; } } return desc ; }


Input: Returns a fresh property descriptor whose standard attributes are guaranteed to be data properties of the right type . Additionally any non - standard enumerable properties of attributes are copied over to the fresh descriptor . [CODESPLIT] function normalizePropertyDescriptor ( attributes ) { var desc = toPropertyDescriptor ( attributes ) ; // Note: no need to call FromGenericPropertyDescriptor(desc), as we represent // "internal" property descriptors as proper Objects from the start for ( var name in attributes ) { if ( ! isStandardAttribute ( name ) ) { Object . defineProperty ( desc , name , { value : attributes [ name ] , writable : true , enumerable : true , configurable : true } ) ; } } return desc ; }


Input: Performs all validation that Object . defineProperty performs without actually defining the property . Returns a boolean indicating whether validation succeeded . [CODESPLIT] function isCompatibleDescriptor ( extensible , current , desc ) { if ( current === undefined && extensible === false ) { return false ; } if ( current === undefined && extensible === true ) { return true ; } if ( isEmptyDescriptor ( desc ) ) { return true ; } if ( isEquivalentDescriptor ( current , desc ) ) { return true ; } if ( current . configurable === false ) { if ( desc . configurable === true ) { return false ; } if ( 'enumerable' in desc && desc . enumerable !== current . enumerable ) { return false ; } } if ( isGenericDescriptor ( desc ) ) { return true ; } if ( isDataDescriptor ( current ) !== isDataDescriptor ( desc ) ) { if ( current . configurable === false ) { return false ; } return true ; } if ( isDataDescriptor ( current ) && isDataDescriptor ( desc ) ) { if ( current . configurable === false ) { if ( current . writable === false && desc . writable === true ) { return false ; } if ( current . writable === false ) { if ( 'value' in desc && ! sameValue ( desc . value , current . value ) ) { return false ; } } } return true ; } if ( isAccessorDescriptor ( current ) && isAccessorDescriptor ( desc ) ) { if ( current . configurable === false ) { if ( 'set' in desc && ! sameValue ( desc . set , current . set ) ) { return false ; } if ( 'get' in desc && ! sameValue ( desc . get , current . get ) ) { return false ; } } } return true ; }


Input: If getTrap returns undefined the caller should perform the default forwarding behavior . If getTrap returns normally otherwise the return value will be a callable trap function . When calling the trap function the caller is responsible for binding its |this| to |this . handler| . [CODESPLIT] function ( trapName ) { var trap = this . handler [ trapName ] ; if ( trap === undefined ) { // the trap was not defined, // perform the default forwarding behavior return undefined ; } if ( typeof trap !== "function" ) { throw new TypeError ( trapName + " trap is not callable: " + trap ) ; } return trap ; }


Input: === fundamental traps === If name denotes a fixed property check : - whether targetHandler reports it as existent - whether the returned descriptor is compatible with the fixed property If the proxy is non - extensible check : - whether name is not a new property Additionally the returned descriptor is normalized and completed . [CODESPLIT] function ( name ) { "use strict" ; var trap = this . getTrap ( "getOwnPropertyDescriptor" ) ; if ( trap === undefined ) { return Reflect . getOwnPropertyDescriptor ( this . target , name ) ; } name = String ( name ) ; var desc = trap . call ( this . handler , this . target , name ) ; desc = normalizeAndCompletePropertyDescriptor ( desc ) ; var targetDesc = Object . getOwnPropertyDescriptor ( this . target , name ) ; var extensible = Object . isExtensible ( this . target ) ; if ( desc === undefined ) { if ( isSealedDesc ( targetDesc ) ) { throw new TypeError ( "cannot report non-configurable property '" + name + "' as non-existent" ) ; } if ( ! extensible && targetDesc !== undefined ) { // if handler is allowed to return undefined, we cannot guarantee // that it will not return a descriptor for this property later. // Once a property has been reported as non-existent on a non-extensible // object, it should forever be reported as non-existent throw new TypeError ( "cannot report existing own property '" + name + "' as non-existent on a non-extensible object" ) ; } return undefined ; } // at this point, we know (desc !== undefined), i.e. // targetHandler reports 'name' as an existing property // Note: we could collapse the following two if-tests into a single // test. Separating out the cases to improve error reporting. if ( ! extensible ) { if ( targetDesc === undefined ) { throw new TypeError ( "cannot report a new own property '" + name + "' on a non-extensible object" ) ; } } if ( name !== undefined ) { if ( ! isCompatibleDescriptor ( extensible , targetDesc , desc ) ) { throw new TypeError ( "cannot report incompatible property descriptor " + "for property '" + name + "'" ) ; } } if ( desc . configurable === false && ! isSealedDesc ( targetDesc ) ) { // if the property is configurable or non-existent on the target, // but is reported as a non-configurable property, it may later be // reported as configurable or non-existent, which violates the // invariant that if the property might change or disappear, the // configurable attribute must be true. throw new TypeError ( "cannot report a non-configurable descriptor " + "for configurable or non-existent property '" + name + "'" ) ; } return desc ; }


Input: In the direct proxies design with refactored prototype climbing this trap is deprecated . For proxies - as - prototypes instead of calling this trap the get set has or enumerate traps are called instead . [CODESPLIT] function ( name ) { var handler = this ; if ( ! handler . has ( name ) ) return undefined ; return { get : function ( ) { return handler . get ( this , name ) ; } , set : function ( val ) { if ( handler . set ( this , name , val ) ) { return val ; } else { throw new TypeError ( "failed assignment to " + name ) ; } } , enumerable : true , configurable : true } ; }


Input: On success check whether the target object is indeed frozen . [CODESPLIT] function ( ) { var trap = this . getTrap ( "freeze" ) ; if ( trap === undefined ) { // default forwarding behavior return Reflect . freeze ( this . target ) ; } var success = trap . call ( this . handler , this . target ) ; success = ! ! success ; // coerce to Boolean if ( success ) { if ( ! Object_isFrozen ( this . target ) ) { throw new TypeError ( "can't report non-frozen object as frozen: " + this . target ) ; } } return success ; }


Input: On success check whether the target object is indeed sealed . [CODESPLIT] function ( ) { var trap = this . getTrap ( "seal" ) ; if ( trap === undefined ) { // default forwarding behavior return Reflect . seal ( this . target ) ; } var success = trap . call ( this . handler , this . target ) ; success = ! ! success ; // coerce to Boolean if ( success ) { if ( ! Object_isSealed ( this . target ) ) { throw new TypeError ( "can't report non-sealed object as sealed: " + this . target ) ; } } return success ; }


Input: On success check whether the target object is indeed non - extensible . [CODESPLIT] function ( ) { var trap = this . getTrap ( "preventExtensions" ) ; if ( trap === undefined ) { // default forwarding behavior return Reflect . preventExtensions ( this . target ) ; } var success = trap . call ( this . handler , this . target ) ; success = ! ! success ; // coerce to Boolean if ( success ) { if ( Object_isExtensible ( this . target ) ) { throw new TypeError ( "can't report extensible object as non-extensible: " + this . target ) ; } } return success ; }


Input: If name denotes a sealed property check whether handler rejects . [CODESPLIT] function ( name ) { "use strict" ; var trap = this . getTrap ( "deleteProperty" ) ; if ( trap === undefined ) { // default forwarding behavior return Reflect . deleteProperty ( this . target , name ) ; } name = String ( name ) ; var res = trap . call ( this . handler , this . target , name ) ; res = ! ! res ; // coerce to Boolean if ( res === true ) { if ( isSealed ( name , this . target ) ) { throw new TypeError ( "property '" + name + "' is non-configurable " + "and can't be deleted" ) ; } } return res ; }


Input: Checks whether the trap result is consistent with the state of the wrapped target . [CODESPLIT] function ( ) { var trap = this . getTrap ( "isExtensible" ) ; if ( trap === undefined ) { // default forwarding behavior return Reflect . isExtensible ( this . target ) ; } var result = trap . call ( this . handler , this . target ) ; result = ! ! result ; // coerce to Boolean var state = Object_isExtensible ( this . target ) ; if ( result !== state ) { if ( result ) { throw new TypeError ( "cannot report non-extensible object as extensible: " + this . target ) ; } else { throw new TypeError ( "cannot report extensible object as non-extensible: " + this . target ) ; } } return state ; }


Input: Check whether the trap result corresponds to the target s [[ Prototype ]] [CODESPLIT] function ( ) { var trap = this . getTrap ( "getPrototypeOf" ) ; if ( trap === undefined ) { // default forwarding behavior return Reflect . getPrototypeOf ( this . target ) ; } var allegedProto = trap . call ( this . handler , this . target ) ; if ( ! Object_isExtensible ( this . target ) ) { var actualProto = Object_getPrototypeOf ( this . target ) ; if ( ! sameValue ( allegedProto , actualProto ) ) { throw new TypeError ( "prototype value does not match: " + this . target ) ; } } return allegedProto ; }


Input: If target is non - extensible and setPrototypeOf trap returns true check whether the trap result corresponds to the target s [[ Prototype ]] [CODESPLIT] function ( newProto ) { var trap = this . getTrap ( "setPrototypeOf" ) ; if ( trap === undefined ) { // default forwarding behavior return Reflect . setPrototypeOf ( this . target , newProto ) ; } var success = trap . call ( this . handler , this . target , newProto ) ; success = ! ! success ; if ( success && ! Object_isExtensible ( this . target ) ) { var actualProto = Object_getPrototypeOf ( this . target ) ; if ( ! sameValue ( newProto , actualProto ) ) { throw new TypeError ( "prototype value does not match: " + this . target ) ; } } return success ; }


Input: === derived traps === If name denotes a fixed property check whether the trap returns true . If name denotes a new property on a non - extensible proxy check whether the trap returns false . [CODESPLIT] function ( name ) { "use strict" ; var trap = this . getTrap ( "hasOwn" ) ; if ( trap === undefined ) { // default forwarding behavior return Reflect . hasOwn ( this . target , name ) ; } name = String ( name ) ; var res = trap . call ( this . handler , this . target , name ) ; res = ! ! res ; // coerce to Boolean if ( res === false ) { if ( isSealed ( name , this . target ) ) { throw new TypeError ( "cannot report existing non-configurable own " + "property '" + name + "' as a non-existent own " + "property" ) ; } if ( ! Object . isExtensible ( this . target ) && isFixed ( name , this . target ) ) { // if handler is allowed to return false, we cannot guarantee // that it will return true for this property later. // Once a property has been reported as non-existent on a non-extensible // object, it should forever be reported as non-existent throw new TypeError ( "cannot report existing own property '" + name + "' as non-existent on a non-extensible object" ) ; } } else { // res === true, if the proxy is non-extensible, // check that name is no new property if ( ! Object . isExtensible ( this . target ) ) { if ( ! isFixed ( name , this . target ) ) { throw new TypeError ( "cannot report a new own property '" + name + "' on a non-extensible object" ) ; } } } return res ; }


Input:
Experimental implementation of the invoke () trap on platforms that support __noSuchMethod__ ( e . g . Spidermonkey / FF ) . / * invoke : function ( receiver name args ) { var trap = this . getTrap ( invoke ) ; if ( trap === undefined ) { default forwarding behavior return Reflect . invoke ( this . target name args receiver ) ; } [CODESPLIT] function ( receiver , name ) { // experimental support for invoke() trap on platforms that // support __noSuchMethod__ /*
    if (name === '__noSuchMethod__') {
      var handler = this;
      return function(name, args) {
        return handler.invoke(receiver, name, args);
      }
    }
    */ var trap = this . getTrap ( "get" ) ; if ( trap === undefined ) { // default forwarding behavior return Reflect . get ( this . target , name , receiver ) ; } name = String ( name ) ; var res = trap . call ( this . handler , this . target , name , receiver ) ; var fixedDesc = Object . getOwnPropertyDescriptor ( this . target , name ) ; // check consistency of the returned value if ( fixedDesc !== undefined ) { // getting an existing property if ( isDataDescriptor ( fixedDesc ) && fixedDesc . configurable === false && fixedDesc . writable === false ) { // own frozen data property if ( ! sameValue ( res , fixedDesc . value ) ) { throw new TypeError ( "cannot report inconsistent value for " + "non-writable, non-configurable property '" + name + "'" ) ; } } else { // it's an accessor property if ( isAccessorDescriptor ( fixedDesc ) && fixedDesc . configurable === false && fixedDesc . get === undefined ) { if ( res !== undefined ) { throw new TypeError ( "must report undefined for non-configurable " + "accessor property '" + name + "' without getter" ) ; } } } } return res ; }


Input: The iterate trap should return an iterator object . [CODESPLIT] function ( ) { var trap = this . getTrap ( "iterate" ) ; if ( trap === undefined ) { // default forwarding behavior return Reflect . iterate ( this . target ) ; } var trapResult = trap . call ( this . handler , this . target ) ; if ( Object ( trapResult ) !== trapResult ) { throw new TypeError ( "iterate trap should return an iterator object, " + "got: " + trapResult ) ; } return trapResult ; }


Input: Any own non - configurable properties of the target that are not included in the trap result give rise to a TypeError . As such we check whether the returned result contains at least all sealed properties of the target object . [CODESPLIT] function ( ) { var trap = this . getTrap ( "keys" ) ; if ( trap === undefined ) { // default forwarding behavior return Reflect . keys ( this . target ) ; } var trapResult = trap . call ( this . handler , this . target ) ; // propNames is used as a set of strings var propNames = Object . create ( null ) ; var numProps = + trapResult . length ; var result = new Array ( numProps ) ; for ( var i = 0 ; i < numProps ; i ++ ) { var s = String ( trapResult [ i ] ) ; if ( propNames [ s ] ) { throw new TypeError ( "keys trap cannot list a " + "duplicate property '" + s + "'" ) ; } if ( ! Object . isExtensible ( this . target ) && ! isFixed ( s , this . target ) ) { // non-extensible proxies don't tolerate new own property names throw new TypeError ( "keys trap cannot list a new " + "property '" + s + "' on a non-extensible object" ) ; } propNames [ s ] = true ; result [ i ] = s ; } var ownEnumerableProps = Object . keys ( this . target ) ; var target = this . target ; ownEnumerableProps . forEach ( function ( ownEnumerableProp ) { if ( ! propNames [ ownEnumerableProp ] ) { if ( isSealed ( ownEnumerableProp , target ) ) { throw new TypeError ( "keys trap failed to include " + "non-configurable enumerable property '" + ownEnumerableProp + "'" ) ; } if ( ! Object . isExtensible ( target ) && isFixed ( ownEnumerableProp , target ) ) { // if handler is allowed not to report ownEnumerableProp as an own // property, we cannot guarantee that it will never report it as // an own property later. Once a property has been reported as // non-existent on a non-extensible object, it should forever be // reported as non-existent throw new TypeError ( "cannot report existing own property '" + ownEnumerableProp + "' as non-existent on a " + "non-extensible object" ) ; } } } ) ; return result ; }


Input: In ES6 this trap is called for all operations that require a list of an object s properties including Object . getOwnPropertyNames and Object . keys . [CODESPLIT] function ( ) { var trap = this . getTrap ( "ownKeys" ) ; if ( trap === undefined ) { // default forwarding behavior return Reflect . ownKeys ( this . target ) ; } var trapResult = trap . call ( this . handler , this . target ) ; if ( trapResult === null || typeof trapResult !== "object" ) { throw new TypeError ( "ownKeys should return an iterator object, got " + trapResult ) ; } return trapResult ; }


Input: New trap that reifies [[ Call ]] . If the target is a function then a call to proxy ( ... args ) Triggers this trap [CODESPLIT] function ( target , thisBinding , args ) { var trap = this . getTrap ( "apply" ) ; if ( trap === undefined ) { return Reflect . apply ( target , thisBinding , args ) ; } if ( typeof this . target === "function" ) { return trap . call ( this . handler , target , thisBinding , args ) ; } else { throw new TypeError ( "apply: " + target + " is not a function" ) ; } }


Input: New trap that reifies [[ Construct ]] . If the target is a function then a call to new proxy ( ... args ) Triggers this trap [CODESPLIT] function ( target , args ) { var trap = this . getTrap ( "construct" ) ; if ( trap === undefined ) { return Reflect . construct ( target , args ) ; } if ( typeof this . target === "function" ) { return trap . call ( this . handler , target , args ) ; } else { throw new TypeError ( "new: " + target + " is not a function" ) ; } }


Input: Checks whether the trap result is consistent with the state of the wrapped target . [CODESPLIT] function ( ) { var trap = this . getTrap ( "isSealed" ) ; if ( trap === undefined ) { // default forwarding behavior return Reflect . isSealed ( this . target ) ; } var result = trap . call ( this . handler , this . target ) ; result = ! ! result ; // coerce to Boolean var state = Object_isSealed ( this . target ) ; if ( result !== state ) { if ( result ) { throw new TypeError ( "cannot report unsealed object as sealed: " + this . target ) ; } else { throw new TypeError ( "cannot report sealed object as unsealed: " + this . target ) ; } } return state ; }


Input: Checks whether the trap result is consistent with the state of the wrapped target . [CODESPLIT] function ( ) { var trap = this . getTrap ( "isFrozen" ) ; if ( trap === undefined ) { // default forwarding behavior return Reflect . isFrozen ( this . target ) ; } var result = trap . call ( this . handler , this . target ) ; result = ! ! result ; // coerce to Boolean var state = Object_isFrozen ( this . target ) ; if ( result !== state ) { if ( result ) { throw new TypeError ( "cannot report unfrozen object as frozen: " + this . target ) ; } else { throw new TypeError ( "cannot report frozen object as unfrozen: " + this . target ) ; } } return state ; }


Input: returns a new function of zero arguments that recursively unwraps any proxies specified as the |this| - value . The primitive is assumed to be a zero - argument method that uses its |this| - binding . [CODESPLIT] function makeUnwrapping0ArgMethod ( primitive ) { return function builtin ( ) { var vHandler = safeWeakMapGet ( directProxies , this ) ; if ( vHandler !== undefined ) { return builtin . call ( vHandler . target ) ; } else { return primitive . call ( this ) ; } } }


Input: imperfect ownKeys implemenation : in ES6 should also include symbol - keyed properties . [CODESPLIT] function ( target ) { var handler = directProxies . get ( target ) ; if ( handler !== undefined ) { return handler . ownKeys ( handler . target ) ; } var result = Reflect . getOwnPropertyNames ( target ) ; var l = + result . length ; var idx = 0 ; return { next : function ( ) { if ( idx === l ) throw StopIteration ; return result [ idx ++ ] ; } } ; }


Input: derived traps [CODESPLIT] function ( target ) { var success = this . preventExtensions ( target ) ; success = ! ! success ; // coerce to Boolean if ( success ) { var props = this . getOwnPropertyNames ( target ) ; var l = + props . length ; for ( var i = 0 ; i < l ; i ++ ) { var name = props [ i ] ; success = success && this . defineProperty ( target , name , { configurable : false } ) ; } } return success ; }


Input: call trap [CODESPLIT] function ( ) { var args = Array . prototype . slice . call ( arguments ) ; return vHandler . apply ( target , this , args ) ; }


Input: load all the contract identifiers into the global scope [CODESPLIT] function load ( obj ) { var name , root ; root = typeof global !== "undefined" && global !== null ? global : this ; for ( name in obj ) { if ( obj . hasOwnProperty ( name ) ) { root [ name ] = obj [ name ] ; } } }


Input: Given a subclass of DS . Model and a JSON object this method will iterate through each attribute of the DS . Model and invoke the DS . Transform#deserialize method on the matching property of the JSON object . This method is typically called after the serializer s normalize method . [CODESPLIT] function ( type , data ) { type . eachTransformedAttribute ( function ( key , type ) { var transform = this . transformFor ( type ) ; data [ key ] = transform . deserialize ( data [ key ] ) ; } , this ) ; return data ; }


Input: SERIALIZE Called when a record is saved in order to convert the record into JSON . [CODESPLIT] function ( record , options ) { var json = { } ; if ( options && options . includeId ) { var id = get ( record , 'id' ) ; if ( id ) { json [ get ( this , 'primaryKey' ) ] = id ; } } record . eachAttribute ( function ( key , attribute ) { this . serializeAttribute ( record , json , key , attribute ) ; } , this ) ; record . eachRelationship ( function ( key , relationship ) { if ( relationship . kind === 'belongsTo' ) { this . serializeBelongsTo ( record , json , relationship ) ; } else if ( relationship . kind === 'hasMany' ) { this . serializeHasMany ( record , json , relationship ) ; } } , this ) ; return json ; }


Input: serializeAttribute can be used to customize how DS . attr properties are serialized [CODESPLIT] function ( record , json , key , attribute ) { var attrs = get ( this , 'attrs' ) ; var value = get ( record , key ) , type = attribute . type ; if ( type ) { var transform = this . transformFor ( type ) ; value = transform . serialize ( value ) ; } // if provided, use the mapping provided by `attrs` in // the serializer key = attrs && attrs [ key ] || ( this . keyForAttribute ? this . keyForAttribute ( key ) : key ) ; json [ key ] = value ; }


Input: serializeBelongsTo can be used to customize how DS . belongsTo properties are serialized . [CODESPLIT] function ( record , json , relationship ) { var key = relationship . key ; var belongsTo = get ( record , key ) ; key = this . keyForRelationship ? this . keyForRelationship ( key , "belongsTo" ) : key ; if ( isNone ( belongsTo ) ) { json [ key ] = belongsTo ; } else { json [ key ] = get ( belongsTo , 'id' ) ; } if ( relationship . options . polymorphic ) { this . serializePolymorphicType ( record , json , relationship ) ; } }


Input: serializeHasMany can be used to customize how DS . hasMany properties are serialized . [CODESPLIT] function ( record , json , relationship ) { var key = relationship . key ; var relationshipType = DS . RelationshipChange . determineRelationshipType ( record . constructor , relationship ) ; if ( relationshipType === 'manyToNone' || relationshipType === 'manyToMany' ) { json [ key ] = get ( record , key ) . mapBy ( 'id' ) ; // TODO support for polymorphic manyToNone and manyToMany relationships } }


Input: EXTRACT The extract method is used to deserialize payload data from the server . By default the JSONSerializer does not push the records into the store . However records that subclass JSONSerializer such as the RESTSerializer may push records into the store as part of the extract call . [CODESPLIT] function ( store , type , payload , id , requestType ) { this . extractMeta ( store , type , payload ) ; var specificExtract = "extract" + requestType . charAt ( 0 ) . toUpperCase ( ) + requestType . substr ( 1 ) ; return this [ specificExtract ] ( store , type , payload , id , requestType ) ; }


Input: extractMeta is used to deserialize any meta information in the adapter payload . By default Ember Data expects meta information to be located on the meta property of the payload object . [CODESPLIT] function ( store , type , payload ) { if ( payload && payload . meta ) { store . metaForType ( type , payload . meta ) ; delete payload . meta ; } }


Input: HELPERS [CODESPLIT] function ( attributeType , skipAssertion ) { var transform = this . container . lookup ( 'transform:' + attributeType ) ; Ember . assert ( "Unable to find transform for '" + attributeType + "'" , skipAssertion || ! ! transform ) ; return transform ; }


Input: Saves all of the records in the RecordArray . [CODESPLIT] function ( ) { var promiseLabel = "DS: RecordArray#save " + get ( this , 'type' ) ; var promise = Ember . RSVP . all ( this . invoke ( "save" ) , promiseLabel ) . then ( function ( array ) { return Ember . A ( array ) ; } , null , "DS: RecordArray#save apply Ember.NativeArray" ) ; return DS . PromiseArray . create ( { promise : promise } ) ; }


Input: Overrides Ember . Array s replace method to implement [CODESPLIT] function ( index , removed , added ) { // Map the array of record objects into an array of  client ids. added = map ( added , function ( record ) { Ember . assert ( "You cannot add '" + record . constructor . typeKey + "' records to this relationship (only '" + this . type . typeKey + "' allowed)" , ! this . type || record instanceof this . type ) ; return record ; } , this ) ; this . _super ( index , removed , added ) ; }


Input: Create a child record within the owner [CODESPLIT] function ( hash ) { var owner = get ( this , 'owner' ) , store = get ( owner , 'store' ) , type = get ( this , 'type' ) , record ; Ember . assert ( "You cannot add '" + type . typeKey + "' records to this polymorphic relationship." , ! get ( this , 'isPolymorphic' ) ) ; record = store . createRecord . call ( store , type , hash ) ; this . pushObject ( record ) ; return record ; }


Input: ..................... . CREATE NEW RECORD . ..................... Create a new record in the current store . The properties passed to this method are set on the newly created record . [CODESPLIT] function ( type , properties ) { type = this . modelFor ( type ) ; properties = copy ( properties ) || { } ; // If the passed properties do not include a primary key, // give the adapter an opportunity to generate one. Typically, // client-side ID generators will use something like uuid.js // to avoid conflicts. if ( isNone ( properties . id ) ) { properties . id = this . _generateId ( type ) ; } // Coerce ID to a string properties . id = coerceId ( properties . id ) ; var record = this . buildRecord ( type , properties . id ) ; // Move the record out of its initial `empty` state into // the `loaded` state. record . loadedData ( ) ; // Set the properties specified on the record. record . setProperties ( properties ) ; return record ; }


Input: If possible this method asks the adapter to generate an ID for a newly created record . [CODESPLIT] function ( type ) { var adapter = this . adapterFor ( type ) ; if ( adapter && adapter . generateIdForRecord ) { return adapter . generateIdForRecord ( this ) ; } return null ; }


Input: ................ . FIND RECORDS . ................ This is the main entry point into finding records . The first parameter to this method is the model s name as a string . [CODESPLIT] function ( type , id ) { if ( id === undefined ) { return this . findAll ( type ) ; } // We are passed a query instead of an id. if ( Ember . typeOf ( id ) === 'object' ) { return this . findQuery ( type , id ) ; } return this . findById ( type , coerceId ( id ) ) ; }


Input: This method returns a record for a given type and id combination . [CODESPLIT] function ( type , id ) { type = this . modelFor ( type ) ; var record = this . recordForId ( type , id ) ; var promise = this . fetchRecord ( record ) || resolve ( record , "DS: Store#findById " + type + " with id: " + id ) ; return promiseObject ( promise ) ; }


Input: This method makes a series of requests to the adapter s find method and returns a promise that resolves once they are all loaded . [CODESPLIT] function ( type , ids ) { var store = this ; var promiseLabel = "DS: Store#findByIds " + type ; return promiseArray ( Ember . RSVP . all ( map ( ids , function ( id ) { return store . findById ( type , id ) ; } ) ) . then ( Ember . A , null , "DS: Store#findByIds of " + type + " complete" ) ) ; }


Input: This method is called by findById if it discovers that a particular type / id pair hasn t been loaded yet to kick off a request to the adapter . [CODESPLIT] function ( record ) { if ( isNone ( record ) ) { return null ; } if ( record . _loadingPromise ) { return record . _loadingPromise ; } if ( ! get ( record , 'isEmpty' ) ) { return null ; } var type = record . constructor , id = get ( record , 'id' ) ; var adapter = this . adapterFor ( type ) ; Ember . assert ( "You tried to find a record but you have no adapter (for " + type + ")" , adapter ) ; Ember . assert ( "You tried to find a record but your adapter (for " + type + ") does not implement 'find'" , adapter . find ) ; var promise = _find ( adapter , this , type , id ) ; record . loadingData ( promise ) ; return promise ; }


Input: This method is called by the record s reload method . [CODESPLIT] function ( record ) { var type = record . constructor , adapter = this . adapterFor ( type ) , id = get ( record , 'id' ) ; Ember . assert ( "You cannot reload a record without an ID" , id ) ; Ember . assert ( "You tried to reload a record but you have no adapter (for " + type + ")" , adapter ) ; Ember . assert ( "You tried to reload a record but your adapter does not implement `find`" , adapter . find ) ; return _find ( adapter , this , type , id ) ; }


Input: This method takes a list of records groups the records by type converts the records into IDs and then invokes the adapter s findMany method . [CODESPLIT] function ( records , owner , resolver ) { if ( ! records . length ) { return ; } // Group By Type var recordsByTypeMap = Ember . MapWithDefault . create ( { defaultValue : function ( ) { return Ember . A ( ) ; } } ) ; forEach ( records , function ( record ) { recordsByTypeMap . get ( record . constructor ) . push ( record ) ; } ) ; forEach ( recordsByTypeMap , function ( type , records ) { var ids = records . mapProperty ( 'id' ) , adapter = this . adapterFor ( type ) ; Ember . assert ( "You tried to load many records but you have no adapter (for " + type + ")" , adapter ) ; Ember . assert ( "You tried to load many records but your adapter does not implement `findMany`" , adapter . findMany ) ; resolver . resolve ( _findMany ( adapter , this , type , ids , owner ) ) ; } , this ) ; }


Input: Returns true if a record for a given type and ID is already loaded . [CODESPLIT] function ( type , id ) { id = coerceId ( id ) ; type = this . modelFor ( type ) ; return ! ! this . typeMapFor ( type ) . idToRecord [ id ] ; }


Input: Returns id record for a given type and ID . If one isn t already loaded it builds a new record and leaves it in the empty state . [CODESPLIT] function ( type , id ) { type = this . modelFor ( type ) ; id = coerceId ( id ) ; var record = this . typeMapFor ( type ) . idToRecord [ id ] ; if ( ! record ) { record = this . buildRecord ( type , id ) ; } return record ; }


Input: If a relationship was originally populated by the adapter as a link ( as opposed to a list of IDs ) this method is called when the relationship is fetched . [CODESPLIT] function ( owner , link , relationship , resolver ) { var adapter = this . adapterFor ( owner . constructor ) ; Ember . assert ( "You tried to load a hasMany relationship but you have no adapter (for " + owner . constructor + ")" , adapter ) ; Ember . assert ( "You tried to load a hasMany relationship from a specified `link` in the original payload but your adapter does not implement `findHasMany`" , adapter . findHasMany ) ; var records = this . recordArrayManager . createManyArray ( relationship . type , Ember . A ( [ ] ) ) ; resolver . resolve ( _findHasMany ( adapter , this , owner , link , relationship ) ) ; return records ; }


Input: This method delegates a query to the adapter . This is the one place where adapter - level semantics are exposed to the application . [CODESPLIT] function ( type , query ) { type = this . modelFor ( type ) ; var array = this . recordArrayManager . createAdapterPopulatedRecordArray ( type , query ) ; var adapter = this . adapterFor ( type ) , promiseLabel = "DS: Store#findQuery " + type , resolver = Ember . RSVP . defer ( promiseLabel ) ; Ember . assert ( "You tried to load a query but you have no adapter (for " + type + ")" , adapter ) ; Ember . assert ( "You tried to load a query but your adapter does not implement `findQuery`" , adapter . findQuery ) ; resolver . resolve ( _findQuery ( adapter , this , type , query , array ) ) ; return promiseArray ( resolver . promise ) ; }


Input: This method returns a filtered array that contains all of the known records for a given type . [CODESPLIT] function ( type ) { type = this . modelFor ( type ) ; var typeMap = this . typeMapFor ( type ) , findAllCache = typeMap . findAllCache ; if ( findAllCache ) { return findAllCache ; } var array = this . recordArrayManager . createRecordArray ( type ) ; typeMap . findAllCache = array ; return array ; }


Input: This method unloads all of the known records for a given type . [CODESPLIT] function ( type ) { type = this . modelFor ( type ) ; var typeMap = this . typeMapFor ( type ) , records = typeMap . records , record ; while ( record = records . pop ( ) ) { record . unloadRecord ( ) ; } typeMap . findAllCache = null ; }


Input: Takes a type and filter function and returns a live RecordArray that remains up to date as new records are loaded into the store or created locally . [CODESPLIT] function ( type , query , filter ) { var promise ; // allow an optional server query if ( arguments . length === 3 ) { promise = this . findQuery ( type , query ) ; } else if ( arguments . length === 2 ) { filter = query ; } type = this . modelFor ( type ) ; var array = this . recordArrayManager . createFilteredRecordArray ( type , filter ) ; promise = promise || resolve ( array ) ; return promiseArray ( promise . then ( function ( ) { return array ; } , null , "DS: Store#filter of " + type ) ) ; }


Input: This method returns if a certain record is already loaded in the store . Use this function to know beforehand if a find () will result in a request or that it will be a cache hit . [CODESPLIT] function ( type , id ) { if ( ! this . hasRecordForId ( type , id ) ) { return false ; } return ! get ( this . recordForId ( type , id ) , 'isEmpty' ) ; }


Input: This method is called at the end of the run loop and flushes any records passed into scheduleSave [CODESPLIT] function ( ) { var pending = this . _pendingSave . slice ( ) ; this . _pendingSave = [ ] ; forEach ( pending , function ( tuple ) { var record = tuple [ 0 ] , resolver = tuple [ 1 ] , adapter = this . adapterFor ( record . constructor ) , operation ; if ( get ( record , 'isNew' ) ) { operation = 'createRecord' ; } else if ( get ( record , 'isDeleted' ) ) { operation = 'deleteRecord' ; } else { operation = 'updateRecord' ; } resolver . resolve ( _commit ( adapter , this , operation , record ) ) ; } , this ) ; }


Input: This method is called once the promise returned by an adapter s createRecord updateRecord or deleteRecord is resolved . [CODESPLIT] function ( record , data ) { if ( data ) { // normalize relationship IDs into records data = normalizeRelationships ( this , record . constructor , data , record ) ; this . updateId ( record , data ) ; } record . adapterDidCommit ( data ) ; }


Input: When an adapter s createRecord updateRecord or deleteRecord resolves with data this method extracts the ID from the supplied data . [CODESPLIT] function ( record , data ) { var oldId = get ( record , 'id' ) , id = coerceId ( data . id ) ; Ember . assert ( "An adapter cannot assign a new id to a record that already has an id. " + record + " had id: " + oldId + " and you tried to update it with " + id + ". This likely happened because your server returned data in response to a find or update that had a different id than the one you sent." , oldId === null || id === oldId ) ; this . typeMapFor ( record . constructor ) . idToRecord [ id ] = record ; set ( record , 'id' , id ) ; }


Input: Returns a map of IDs to client IDs for a given type . [CODESPLIT] function ( type ) { var typeMaps = get ( this , 'typeMaps' ) , guid = Ember . guidFor ( type ) , typeMap ; typeMap = typeMaps [ guid ] ; if ( typeMap ) { return typeMap ; } typeMap = { idToRecord : { } , records : [ ] , metadata : { } } ; typeMaps [ guid ] = typeMap ; return typeMap ; }


Input: ................ . LOADING DATA . ................ This internal method is used by push . [CODESPLIT] function ( type , data , partial ) { var id = coerceId ( data . id ) , record = this . recordForId ( type , id ) ; record . setupData ( data , partial ) ; this . recordArrayManager . recordDidChange ( record ) ; return record ; }


Input: Returns a model class for a particular key . Used by methods that take a type key ( like find createRecord etc . ) [CODESPLIT] function ( key ) { var factory ; if ( typeof key === 'string' ) { var normalizedKey = this . container . normalize ( 'model:' + key ) ; factory = this . container . lookupFactory ( normalizedKey ) ; if ( ! factory ) { throw new Ember . Error ( "No model was found for '" + key + "'" ) ; } factory . typeKey = normalizedKey . split ( ':' , 2 ) [ 1 ] ; } else { // A factory already supplied. factory = key ; } factory . store = this ; return factory ; }


Input: Push some data for a given type into the store . [CODESPLIT] function ( type , data , _partial ) { // _partial is an internal param used by `update`. // If passed, it means that the data should be // merged into the existing data, not replace it. Ember . assert ( "You must include an `id` in a hash passed to `push`" , data . id != null ) ; type = this . modelFor ( type ) ; // normalize relationship IDs into records data = normalizeRelationships ( this , type , data ) ; this . _load ( type , data , _partial ) ; return this . recordForId ( type , data . id ) ; }


Input: Push some raw data into the store . [CODESPLIT] function ( type , payload ) { var serializer ; if ( ! payload ) { payload = type ; serializer = defaultSerializer ( this . container ) ; Ember . assert ( "You cannot use `store#pushPayload` without a type unless your default serializer defines `pushPayload`" , serializer . pushPayload ) ; } else { serializer = this . serializerFor ( type ) ; } serializer . pushPayload ( this , payload ) ; }


Input: If you have some metadata to set for a type you can call metaForType . [CODESPLIT] function ( type , metadata ) { type = this . modelFor ( type ) ; Ember . merge ( this . typeMapFor ( type ) . metadata , metadata ) ; }


Input: Build a brand new record for a given type ID and initial data . [CODESPLIT] function ( type , id , data ) { var typeMap = this . typeMapFor ( type ) , idToRecord = typeMap . idToRecord ; Ember . assert ( 'The id ' + id + ' has already been used with another record of type ' + type . toString ( ) + '.' , ! id || ! idToRecord [ id ] ) ; // lookupFactory should really return an object that creates // instances with the injections applied var record = type . _create ( { id : id , store : this , container : this . container } ) ; if ( data ) { record . setupData ( data ) ; } // if we're creating an item, this process will be done // later, once the object has been persisted. if ( id ) { idToRecord [ id ] = record ; } typeMap . records . push ( record ) ; return record ; }


Input: ............... . DESTRUCTION . ............... When a record is destroyed this un - indexes it and removes it from any record arrays so it can be GCed . [CODESPLIT] function ( record ) { var type = record . constructor , typeMap = this . typeMapFor ( type ) , id = get ( record , 'id' ) ; record . updateRecordArrays ( ) ; if ( id ) { delete typeMap . idToRecord [ id ] ; } var loc = indexOf ( typeMap . records , record ) ; typeMap . records . splice ( loc , 1 ) ; }


Input: ........................ . RELATIONSHIP CHANGES . ........................ [CODESPLIT] function ( childRecord , childKey , parentRecord , parentKey , change ) { var clientId = childRecord . clientId , parentClientId = parentRecord ? parentRecord : parentRecord ; var key = childKey + parentKey ; var changes = this . _relationshipChanges ; if ( ! ( clientId in changes ) ) { changes [ clientId ] = { } ; } if ( ! ( parentClientId in changes [ clientId ] ) ) { changes [ clientId ] [ parentClientId ] = { } ; } if ( ! ( key in changes [ clientId ] [ parentClientId ] ) ) { changes [ clientId ] [ parentClientId ] [ key ] = { } ; } changes [ clientId ] [ parentClientId ] [ key ] [ change . changeType ] = change ; }


Input: ...................... . PER - TYPE ADAPTERS ...................... Returns the adapter for a given type . [CODESPLIT] function ( type ) { var container = this . container , adapter ; if ( container ) { adapter = container . lookup ( 'adapter:' + type . typeKey ) || container . lookup ( 'adapter:application' ) ; } return adapter || get ( this , 'defaultAdapter' ) ; }


Input: .............................. . RECORD CHANGE NOTIFICATION . .............................. Returns an instance of the serializer for a given type . For example serializerFor ( person ) will return an instance of App . PersonSerializer . [CODESPLIT] function ( type ) { type = this . modelFor ( type ) ; var adapter = this . adapterFor ( type ) ; return serializerFor ( this . container , type . typeKey , adapter && adapter . defaultSerializer ) ; }


Input: If there are any unsaved records that are in a hasMany they won t be in the payload so add them back in manually . [CODESPLIT] function addUnsavedRecords ( record , key , data ) { if ( record ) { data . pushObjects ( record . get ( key ) . filterBy ( 'isNew' ) ) ; } }


Input: / * This file encapsulates the various states that a record can transition through during its lifecycle . ### State [CODESPLIT] function ( object ) { // Ignore internal property defined by simulated `Ember.create`. var names = Ember . keys ( object ) ; var i , l , name ; for ( i = 0 , l = names . length ; i < l ; i ++ ) { name = names [ i ] ; if ( object . hasOwnProperty ( name ) && object [ name ] ) { return true ; } } return false ; }


Input: The created and updated states are created outside the state chart so we can reopen their substates and add mixins as necessary . [CODESPLIT] function deepClone ( object ) { var clone = { } , value ; for ( var prop in object ) { value = object [ prop ] ; if ( value && typeof value === 'object' ) { clone [ prop ] = deepClone ( value ) ; } else { clone [ prop ] = value ; } } return clone ; }


Input: Adds error messages to a given attribute and sends becameInvalid event to the record . [CODESPLIT] function ( attribute , messages ) { var wasEmpty = get ( this , 'isEmpty' ) ; messages = this . _findOrCreateMessages ( attribute , messages ) ; get ( this , 'content' ) . addObjects ( messages ) ; this . notifyPropertyChange ( attribute ) ; this . enumerableContentDidChange ( ) ; if ( wasEmpty && ! get ( this , 'isEmpty' ) ) { this . trigger ( 'becameInvalid' ) ; } }


Input: Removes all error messages from the given attribute and sends becameValid event to the record if there no more errors left . [CODESPLIT] function ( attribute ) { if ( get ( this , 'isEmpty' ) ) { return ; } var content = get ( this , 'content' ) . rejectBy ( 'attribute' , attribute ) ; get ( this , 'content' ) . setObjects ( content ) ; this . notifyPropertyChange ( attribute ) ; this . enumerableContentDidChange ( ) ; if ( get ( this , 'isEmpty' ) ) { this . trigger ( 'becameValid' ) ; } }


Input: Use [ DS . JSONSerializer ] ( DS . JSONSerializer . html ) to get the JSON representation of a record . [CODESPLIT] function ( options ) { // container is for lazy transform lookups var serializer = DS . JSONSerializer . create ( { container : this . container } ) ; return serializer . serialize ( this , options ) ; }


Input: Returns an object whose keys are changed properties and value is an [ oldProp newProp ] array . [CODESPLIT] function ( ) { var oldData = get ( this , '_data' ) , newData = get ( this , '_attributes' ) , diffData = { } , prop ; for ( prop in newData ) { diffData [ prop ] = [ oldData [ prop ] , newData [ prop ] ] ; } return diffData ; }


Input: If the adapter did not return a hash in response to a commit merge the changed attributes and relationships into the existing saved data . [CODESPLIT] function ( data ) { set ( this , 'isError' , false ) ; if ( data ) { this . _data = data ; } else { Ember . mixin ( this . _data , this . _inFlightAttributes ) ; } this . _inFlightAttributes = { } ; this . send ( 'didCommit' ) ; this . updateRecordArraysLater ( ) ; if ( ! data ) { return ; } this . suspendRelationshipObservers ( function ( ) { this . notifyPropertyChange ( 'data' ) ; } ) ; }


Input: If the model isDirty this function will which discard any unsaved changes [CODESPLIT] function ( ) { this . _attributes = { } ; if ( get ( this , 'isError' ) ) { this . _inFlightAttributes = { } ; set ( this , 'isError' , false ) ; } if ( ! get ( this , 'isValid' ) ) { this . _inFlightAttributes = { } ; } this . send ( 'rolledBack' ) ; this . suspendRelationshipObservers ( function ( ) { this . notifyPropertyChange ( 'data' ) ; } ) ; }


Input: The goal of this method is to temporarily disable specific observers that take action in response to application changes . [CODESPLIT] function ( callback , binding ) { var observers = get ( this . constructor , 'relationshipNames' ) . belongsTo ; var self = this ; try { this . _suspendedRelationships = true ; Ember . _suspendObservers ( self , observers , null , 'belongsToDidChange' , function ( ) { Ember . _suspendBeforeObservers ( self , observers , null , 'belongsToWillChange' , function ( ) { callback . call ( binding || self ) ; } ) ; } ) ; } finally { this . _suspendedRelationships = false ; } }


Input: Save the record and persist any changes to the record to an extenal source via the adapter . [CODESPLIT] function ( ) { var promiseLabel = "DS: Model#save " + this ; var resolver = Ember . RSVP . defer ( promiseLabel ) ; this . get ( 'store' ) . scheduleSave ( this , resolver ) ; this . _inFlightAttributes = this . _attributes ; this . _attributes = { } ; return DS . PromiseObject . create ( { promise : resolver . promise } ) ; }


Input: Reload the record from the adapter . [CODESPLIT] function ( ) { set ( this , 'isReloading' , true ) ; var record = this ; var promiseLabel = "DS: Model#reload of " + this ; var promise = new Ember . RSVP . Promise ( function ( resolve ) { record . send ( 'reloadRecord' , resolve ) ; } , promiseLabel ) . then ( function ( ) { record . set ( 'isReloading' , false ) ; record . set ( 'isError' , false ) ; return record ; } , function ( reason ) { record . set ( 'isError' , true ) ; throw reason ; } , "DS: Model#reload complete, update flags" ) ; return DS . PromiseObject . create ( { promise : promise } ) ; }


Input: FOR USE DURING COMMIT PROCESS [CODESPLIT] function ( attributeName , value ) { // If a value is passed in, update the internal attributes and clear // the attribute cache so it picks up the new value. Otherwise, // collapse the current value into the internal attributes because // the adapter has acknowledged it. if ( value !== undefined ) { this . _data [ attributeName ] = value ; this . notifyPropertyChange ( attributeName ) ; } else { this . _data [ attributeName ] = this . _inFlightAttributes [ attributeName ] ; } this . updateRecordArraysLater ( ) ; }


Input: Override the default event firing from Ember . Evented to also call methods with the given name . [CODESPLIT] function ( name ) { Ember . tryInvoke ( this , name , [ ] . slice . call ( arguments , 1 ) ) ; this . _super . apply ( this , arguments ) ; }


Input: Iterates through the attributes of the model calling the passed function on each attribute . [CODESPLIT] function ( callback , binding ) { get ( this , 'attributes' ) . forEach ( function ( name , meta ) { callback . call ( binding , name , meta ) ; } , binding ) ; }


Input: Iterates through the transformedAttributes of the model calling the passed function on each attribute . Note the callback will not be called for any attributes that do not have an transformation type . [CODESPLIT] function ( callback , binding ) { get ( this , 'transformedAttributes' ) . forEach ( function ( name , type ) { callback . call ( binding , name , type ) ; } ) ; }


Input: This Ember . js hook allows an object to be notified when a property is defined . [CODESPLIT] function ( proto , key , value ) { // Check if the value being set is a computed property. if ( value instanceof Ember . Descriptor ) { // If it is, get the metadata for the relationship. This is // populated by the `DS.belongsTo` helper when it is creating // the computed property. var meta = value . meta ( ) ; if ( meta . isRelationship && meta . kind === 'belongsTo' ) { Ember . addObserver ( proto , key , null , 'belongsToDidChange' ) ; Ember . addBeforeObserver ( proto , key , null , 'belongsToWillChange' ) ; } meta . parentType = proto . constructor ; } }


Input: Given a callback iterates over each of the relationships in the model invoking the callback with the name of each relationship and its relationship descriptor . [CODESPLIT] function ( callback , binding ) { get ( this , 'relationshipsByName' ) . forEach ( function ( name , relationship ) { callback . call ( binding , name , relationship ) ; } ) ; }


Input: This method is invoked whenever data is loaded into the store by the adapter or updated by the adapter or when a record has changed . [CODESPLIT] function ( ) { forEach ( this . changedRecords , function ( record ) { if ( get ( record , 'isDeleted' ) ) { this . _recordWasDeleted ( record ) ; } else { this . _recordWasChanged ( record ) ; } } , this ) ; this . changedRecords = [ ] ; }


Input: Update an individual filter . [CODESPLIT] function ( array , filter , type , record ) { var shouldBeInArray ; if ( ! filter ) { shouldBeInArray = true ; } else { shouldBeInArray = filter ( record ) ; } var recordArrays = this . recordArraysForRecord ( record ) ; if ( shouldBeInArray ) { recordArrays . add ( array ) ; array . addRecord ( record ) ; } else if ( ! shouldBeInArray ) { recordArrays . remove ( array ) ; array . removeRecord ( record ) ; } }


Input: This method is invoked if the filterFunction property is changed on a DS . FilteredRecordArray . [CODESPLIT] function ( array , type , filter ) { var typeMap = this . store . typeMapFor ( type ) , records = typeMap . records , record ; for ( var i = 0 , l = records . length ; i < l ; i ++ ) { record = records [ i ] ; if ( ! get ( record , 'isDeleted' ) && ! get ( record , 'isEmpty' ) ) { this . updateRecordArray ( array , filter , type , record ) ; } } }


Input: Create a DS . ManyArray for a type and list of record references and index the ManyArray under each reference . This allows us to efficiently remove records from ManyArray s when they are deleted . [CODESPLIT] function ( type , records ) { var manyArray = DS . ManyArray . create ( { type : type , content : records , store : this . store } ) ; forEach ( records , function ( record ) { var arrays = this . recordArraysForRecord ( record ) ; arrays . add ( manyArray ) ; } , this ) ; return manyArray ; }


Input: Create a DS . RecordArray for a type and register it for updates . [CODESPLIT] function ( type ) { var array = DS . RecordArray . create ( { type : type , content : Ember . A ( ) , store : this . store , isLoaded : true } ) ; this . registerFilteredRecordArray ( array , type ) ; return array ; }


Input: Create a DS . FilteredRecordArray for a type and register it for updates . [CODESPLIT] function ( type , filter ) { var array = DS . FilteredRecordArray . create ( { type : type , content : Ember . A ( ) , store : this . store , manager : this , filterFunction : filter } ) ; this . registerFilteredRecordArray ( array , type , filter ) ; return array ; }


Input: Create a DS . AdapterPopulatedRecordArray for a type with given query . [CODESPLIT] function ( type , query ) { return DS . AdapterPopulatedRecordArray . create ( { type : type , query : query , content : Ember . A ( ) , store : this . store } ) ; }


Input: Register a RecordArray for a given type to be backed by a filter function . This will cause the array to update automatically when records of that type change attribute values or states . [CODESPLIT] function ( array , type , filter ) { var recordArrays = this . filteredRecordArrays . get ( type ) ; recordArrays . push ( array ) ; this . updateFilter ( array , type , filter ) ; }


Input: Internally we maintain a map of all unloaded IDs requested by a ManyArray . As the adapter loads data into the store the store notifies any interested ManyArrays . When the ManyArray s total number of loading records drops to zero it becomes isLoaded and fires a didLoad event . [CODESPLIT] function ( record , array ) { var loadingRecordArrays = record . _loadingRecordArrays || [ ] ; loadingRecordArrays . push ( array ) ; record . _loadingRecordArrays = loadingRecordArrays ; }


Input: Proxies to the serializer s serialize method . [CODESPLIT] function ( record , options ) { return get ( record , 'store' ) . serializerFor ( record . constructor . typeKey ) . serialize ( record , options ) ; }


Input: Find multiple records at once . [CODESPLIT] function ( store , type , ids ) { var promises = map . call ( ids , function ( id ) { return this . find ( store , type , id ) ; } , this ) ; return Ember . RSVP . all ( promises ) ; }


Input: Implement this method in order to provide data associated with a type [CODESPLIT] function ( type ) { if ( type . FIXTURES ) { var fixtures = Ember . A ( type . FIXTURES ) ; return fixtures . map ( function ( fixture ) { var fixtureIdType = typeof fixture . id ; if ( fixtureIdType !== "number" && fixtureIdType !== "string" ) { throw new Error ( fmt ( 'the id property must be defined as a number or string for fixture %@' , [ fixture ] ) ) ; } fixture . id = fixture . id + '' ; return fixture ; } ) ; } return null ; }


Input: Implement this method in order to provide json for CRUD methods [CODESPLIT] function ( store , type , record ) { return store . serializerFor ( type ) . serialize ( record , { includeId : true } ) ; }


Input: / * [CODESPLIT] function ( type , record ) { var existingFixture = this . findExistingFixture ( type , record ) ; if ( existingFixture ) { var index = indexOf ( type . FIXTURES , existingFixture ) ; type . FIXTURES . splice ( index , 1 ) ; return true ; } }


Input: / * [CODESPLIT] function ( type , record ) { var fixtures = this . fixturesForType ( type ) ; var id = get ( record , 'id' ) ; return this . findFixtureById ( fixtures , id ) ; }


Input: / * [CODESPLIT] function ( fixtures , id ) { return Ember . A ( fixtures ) . find ( function ( r ) { if ( '' + get ( r , 'id' ) === '' + id ) { return true ; } else { return false ; } } ) ; }


Input: If you want to do normalizations specific to some part of the payload you can specify those under normalizeHash . [CODESPLIT] function ( type , hash , prop ) { this . normalizeId ( hash ) ; this . normalizeAttributes ( type , hash ) ; this . normalizeRelationships ( type , hash ) ; this . normalizeUsingDeclaredMapping ( type , hash ) ; if ( this . normalizeHash && this . normalizeHash [ prop ] ) { this . normalizeHash [ prop ] ( hash ) ; } return this . _super ( type , hash , prop ) ; }


Input: Called when the server has returned a payload representing a single record such as in response to a find or save . [CODESPLIT] function ( store , primaryType , payload , recordId , requestType ) { payload = this . normalizePayload ( primaryType , payload ) ; var primaryTypeName = primaryType . typeKey , primaryRecord ; for ( var prop in payload ) { var typeName = this . typeForRoot ( prop ) , isPrimary = typeName === primaryTypeName ; // legacy support for singular resources if ( isPrimary && Ember . typeOf ( payload [ prop ] ) !== "array" ) { primaryRecord = this . normalize ( primaryType , payload [ prop ] , prop ) ; continue ; } var type = store . modelFor ( typeName ) ; /*jshint loopfunc:true*/ forEach . call ( payload [ prop ] , function ( hash ) { var typeName = this . typeForRoot ( prop ) , type = store . modelFor ( typeName ) , typeSerializer = store . serializerFor ( type ) ; hash = typeSerializer . normalize ( type , hash , prop ) ; var isFirstCreatedRecord = isPrimary && ! recordId && ! primaryRecord , isUpdatedRecord = isPrimary && coerceId ( hash . id ) === recordId ; // find the primary record. // // It's either: // * the record with the same ID as the original request // * in the case of a newly created record that didn't have an ID, the first //   record in the Array if ( isFirstCreatedRecord || isUpdatedRecord ) { primaryRecord = hash ; } else { store . push ( typeName , hash ) ; } } , this ) ; } return primaryRecord ; }


Input: Called when the server has returned a payload representing multiple records such as in response to a findAll or findQuery . [CODESPLIT] function ( store , primaryType , payload ) { payload = this . normalizePayload ( primaryType , payload ) ; var primaryTypeName = primaryType . typeKey , primaryArray ; for ( var prop in payload ) { var typeKey = prop , forcedSecondary = false ; if ( prop . charAt ( 0 ) === '_' ) { forcedSecondary = true ; typeKey = prop . substr ( 1 ) ; } var typeName = this . typeForRoot ( typeKey ) , type = store . modelFor ( typeName ) , typeSerializer = store . serializerFor ( type ) , isPrimary = ( ! forcedSecondary && ( typeName === primaryTypeName ) ) ; /*jshint loopfunc:true*/ var normalizedArray = map . call ( payload [ prop ] , function ( hash ) { return typeSerializer . normalize ( type , hash , prop ) ; } , this ) ; if ( isPrimary ) { primaryArray = normalizedArray ; } else { store . pushMany ( typeName , normalizedArray ) ; } } return primaryArray ; }


Input: This method allows you to push a payload containing top - level collections of records organized per type . [CODESPLIT] function ( store , payload ) { payload = this . normalizePayload ( null , payload ) ; for ( var prop in payload ) { var typeName = this . typeForRoot ( prop ) , type = store . modelFor ( typeName ) ; /*jshint loopfunc:true*/ var normalizedArray = map . call ( Ember . makeArray ( payload [ prop ] ) , function ( hash ) { return this . normalize ( type , hash , prop ) ; } , this ) ; store . pushMany ( typeName , normalizedArray ) ; } }


Input: You can use this method to customize the root keys serialized into the JSON . By default the REST Serializer sends camelized root keys . For example your server may expect underscored root objects . [CODESPLIT] function ( hash , type , record , options ) { hash [ type . typeKey ] = this . serialize ( record , options ) ; }


Input: You can use this method to customize how polymorphic objects are serialized . By default the JSON Serializer creates the key by appending Type to the attribute and value from the model s camelcased model name . [CODESPLIT] function ( record , json , relationship ) { var key = relationship . key , belongsTo = get ( record , key ) ; key = this . keyForAttribute ? this . keyForAttribute ( key ) : key ; json [ key + "Type" ] = belongsTo . constructor . typeKey ; }


Input: Called by the store in order to fetch a JSON array for all of the records for a given type . [CODESPLIT] function ( store , type , sinceToken ) { var query ; if ( sinceToken ) { query = { since : sinceToken } ; } return this . ajax ( this . buildURL ( type . typeKey ) , 'GET' , { data : query } ) ; }


Input: Called by the store in order to fetch a JSON array for the unloaded records in a has - many relationship that were originally specified as IDs . [CODESPLIT] function ( store , type , ids ) { return this . ajax ( this . buildURL ( type . typeKey ) , 'GET' , { data : { ids : ids } } ) ; }


Input: Called by the store in order to fetch a JSON array for the unloaded records in a has - many relationship that were originally specified as a URL ( inside of links ) . [CODESPLIT] function ( store , record , url ) { var host = get ( this , 'host' ) , id = get ( record , 'id' ) , type = record . constructor . typeKey ; if ( host && url . charAt ( 0 ) === '/' && url . charAt ( 1 ) !== '/' ) { url = host + url ; } return this . ajax ( this . urlPrefix ( url , this . buildURL ( type , id ) ) , 'GET' ) ; }


Input: Called by the store in order to fetch a JSON array for the unloaded records in a belongs - to relationship that were originally specified as a URL ( inside of links ) . [CODESPLIT] function ( store , record , url ) { var id = get ( record , 'id' ) , type = record . constructor . typeKey ; return this . ajax ( this . urlPrefix ( url , this . buildURL ( type , id ) ) , 'GET' ) ; }


Input: Called by the store when a newly created record is saved via the save method on a model record instance . [CODESPLIT] function ( store , type , record ) { var data = { } ; var serializer = store . serializerFor ( type . typeKey ) ; serializer . serializeIntoHash ( data , type , record , { includeId : true } ) ; return this . ajax ( this . buildURL ( type . typeKey ) , "POST" , { data : data } ) ; }


Input: Called by the store when an existing record is saved via the save method on a model record instance . [CODESPLIT] function ( store , type , record ) { var data = { } ; var serializer = store . serializerFor ( type . typeKey ) ; serializer . serializeIntoHash ( data , type , record ) ; var id = get ( record , 'id' ) ; return this . ajax ( this . buildURL ( type . typeKey , id ) , "PUT" , { data : data } ) ; }


Input: Called by the store when a record is deleted . [CODESPLIT] function ( store , type , record ) { var id = get ( record , 'id' ) ; return this . ajax ( this . buildURL ( type . typeKey , id ) , "DELETE" ) ; }


Input: Builds a URL for a given type and optional ID . [CODESPLIT] function ( type , id ) { var url = [ ] , host = get ( this , 'host' ) , prefix = this . urlPrefix ( ) ; if ( type ) { url . push ( this . pathForType ( type ) ) ; } if ( id ) { url . push ( id ) ; } if ( prefix ) { url . unshift ( prefix ) ; } url = url . join ( '/' ) ; if ( ! host && url ) { url = '/' + url ; } return url ; }


Input: Takes a URL an HTTP method and a hash of data and makes an HTTP request . [CODESPLIT] function ( url , type , hash ) { var adapter = this ; return new Ember . RSVP . Promise ( function ( resolve , reject ) { hash = adapter . ajaxOptions ( url , type , hash ) ; hash . success = function ( json ) { Ember . run ( null , resolve , json ) ; } ; hash . error = function ( jqXHR , textStatus , errorThrown ) { Ember . run ( null , reject , adapter . ajaxError ( jqXHR ) ) ; } ; Ember . $ . ajax ( hash ) ; } , "DS: RestAdapter#ajax " + type + " to " + url ) ; }


Input: Inflector . Ember provides a mechanism for supplying inflection rules for your application . Ember includes a default set of inflection rules and provides an API for providing additional rules . [CODESPLIT] function Inflector ( ruleSet ) { ruleSet = ruleSet || { } ; ruleSet . uncountable = ruleSet . uncountable || { } ; ruleSet . irregularPairs = ruleSet . irregularPairs || { } ; var rules = this . rules = { plurals : ruleSet . plurals || [ ] , singular : ruleSet . singular || [ ] , irregular : { } , irregularInverse : { } , uncountable : { } } ; loadUncountable ( rules , ruleSet . uncountable ) ; loadIrregular ( rules , ruleSet . irregularPairs ) ; }


Input: @protected [CODESPLIT] function ( word , typeRules , irregular ) { var inflection , substitution , result , lowercase , isBlank , isUncountable , isIrregular , isIrregularInverse , rule ; isBlank = BLANK_REGEX . test ( word ) ; if ( isBlank ) { return word ; } lowercase = word . toLowerCase ( ) ; isUncountable = this . rules . uncountable [ lowercase ] ; if ( isUncountable ) { return word ; } isIrregular = irregular && irregular [ lowercase ] ; if ( isIrregular ) { return isIrregular ; } for ( var i = typeRules . length , min = 0 ; i > min ; i -- ) { inflection = typeRules [ i - 1 ] ; rule = inflection [ 0 ] ; if ( rule . test ( word ) ) { break ; } } inflection = inflection || [ ] ; rule = inflection [ 0 ] ; substitution = inflection [ 1 ] ; result = word . replace ( rule , substitution ) ; return result ; }


Input: Underscores relationship names and appends _id or _ids when serializing relationship keys . [CODESPLIT] function ( key , kind ) { key = Ember . String . decamelize ( key ) ; if ( kind === "belongsTo" ) { return key + "_id" ; } else if ( kind === "hasMany" ) { return Ember . String . singularize ( key ) + "_ids" ; } else { return key ; } }


Input: Underscores the JSON root keys when serializing . [CODESPLIT] function ( data , type , record , options ) { var root = Ember . String . decamelize ( type . typeKey ) ; data [ root ] = this . serialize ( record , options ) ; }


Input: Serializes a polymorphic type as a fully capitalized model name . [CODESPLIT] function ( record , json , relationship ) { var key = relationship . key , belongsTo = get ( record , key ) ; key = this . keyForAttribute ( key ) ; json [ key + "_type" ] = Ember . String . capitalize ( belongsTo . constructor . typeKey ) ; }


Input: EXTRACT Extracts the model typeKey from underscored root objects . [CODESPLIT] function ( root ) { var camelized = Ember . String . camelize ( root ) ; return Ember . String . singularize ( camelized ) ; }


Input: Convert snake_cased links to camelCase [CODESPLIT] function ( data ) { if ( data . links ) { var links = data . links ; for ( var link in links ) { var camelizedLink = Ember . String . camelize ( link ) ; if ( camelizedLink !== link ) { links [ camelizedLink ] = links [ link ] ; delete links [ link ] ; } } } }


Input: Normalize the polymorphic type from the JSON . [CODESPLIT] function ( type , hash ) { var payloadKey , payload ; if ( this . keyForRelationship ) { type . eachRelationship ( function ( key , relationship ) { if ( relationship . options . polymorphic ) { payloadKey = this . keyForAttribute ( key ) ; payload = hash [ payloadKey ] ; if ( payload && payload . type ) { payload . type = this . typeForRoot ( payload . type ) ; } else if ( payload && relationship . kind === "hasMany" ) { var self = this ; forEach ( payload , function ( single ) { single . type = self . typeForRoot ( single . type ) ; } ) ; } } else { payloadKey = this . keyForRelationship ( key , relationship . kind ) ; payload = hash [ payloadKey ] ; } hash [ key ] = payload ; if ( key !== payloadKey ) { delete hash [ payloadKey ] ; } } , this ) ; } }


Input: Serialize has - may relationship when it is configured as embedded objects . [CODESPLIT] function ( record , json , relationship ) { var key = relationship . key , attrs = get ( this , 'attrs' ) , embed = attrs && attrs [ key ] && attrs [ key ] . embedded === 'always' ; if ( embed ) { json [ this . keyForAttribute ( key ) ] = get ( record , key ) . map ( function ( relation ) { var data = relation . serialize ( ) , primaryKey = get ( this , 'primaryKey' ) ; data [ primaryKey ] = get ( relation , primaryKey ) ; return data ; } , this ) ; } }


Input: Extract embedded objects out of the payload for a single object and add them as sideloaded objects instead . [CODESPLIT] function ( store , primaryType , payload , recordId , requestType ) { var root = this . keyForAttribute ( primaryType . typeKey ) , partial = payload [ root ] ; updatePayloadWithEmbedded ( store , this , primaryType , partial , payload ) ; return this . _super ( store , primaryType , payload , recordId , requestType ) ; }


Input: Extract embedded objects out of a standard payload and add them as sideloaded objects instead . [CODESPLIT] function ( store , type , payload ) { var root = this . keyForAttribute ( type . typeKey ) , partials = payload [ Ember . String . pluralize ( root ) ] ; forEach ( partials , function ( partial ) { updatePayloadWithEmbedded ( store , this , type , partial , payload ) ; } , this ) ; return this . _super ( store , type , payload ) ; }


Input: The ActiveModelAdapter overrides the pathForType method to build underscored URLs by decamelizing and pluralizing the object type name . [CODESPLIT] function ( type ) { var decamelized = Ember . String . decamelize ( type ) ; return Ember . String . pluralize ( decamelized ) ; }


Input: The ActiveModelAdapter overrides the ajaxError method to return a DS . InvalidError for all 422 Unprocessable Entity responses . [CODESPLIT] function ( jqXHR ) { var error = this . _super ( jqXHR ) ; if ( jqXHR && jqXHR . status === 422 ) { var jsonErrors = Ember . $ . parseJSON ( jqXHR . responseText ) [ "errors" ] , errors = { } ; forEach ( Ember . keys ( jsonErrors ) , function ( key ) { errors [ Ember . String . camelize ( key ) ] = jsonErrors [ key ] ; } ) ; return new DS . InvalidError ( errors ) ; } else { return error ; } }


Input: @ngdoc function @name angular . extend @function [CODESPLIT] function extend ( dst ) { var h = dst . $$hashKey ; forEach ( arguments , function ( obj ) { if ( obj !== dst ) { forEach ( obj , function ( value , key ) { dst [ key ] = value ; } ) ; } } ) ; setHashKey ( dst , h ) ; return dst ; }


Input: @ngdoc function @name angular . copy @function [CODESPLIT] function copy ( source , destination ) { if ( isWindow ( source ) || isScope ( source ) ) { throw ngMinErr ( 'cpws' , "Can't copy! Making copies of Window or Scope instances is not supported." ) ; } if ( ! destination ) { destination = source ; if ( source ) { if ( isArray ( source ) ) { destination = copy ( source , [ ] ) ; } else if ( isDate ( source ) ) { destination = new Date ( source . getTime ( ) ) ; } else if ( isRegExp ( source ) ) { destination = new RegExp ( source . source ) ; } else if ( isObject ( source ) ) { destination = copy ( source , { } ) ; } } } else { if ( source === destination ) throw ngMinErr ( 'cpi' , "Can't copy! Source and destination are identical." ) ; if ( isArray ( source ) ) { destination . length = 0 ; for ( var i = 0 ; i < source . length ; i ++ ) { destination . push ( copy ( source [ i ] ) ) ; } } else { var h = destination . $$hashKey ; forEach ( destination , function ( value , key ) { delete destination [ key ] ; } ) ; for ( var key in source ) { destination [ key ] = copy ( source [ key ] ) ; } setHashKey ( destination , h ) ; } } return destination ; }


Input: Parses an escaped url query string into key - value pairs . [CODESPLIT] function parseKeyValue ( /**string*/ keyValue ) { var obj = { } , key_value , key ; forEach ( ( keyValue || "" ) . split ( '&' ) , function ( keyValue ) { if ( keyValue ) { key_value = keyValue . split ( '=' ) ; key = tryDecodeURIComponent ( key_value [ 0 ] ) ; if ( isDefined ( key ) ) { var val = isDefined ( key_value [ 1 ] ) ? tryDecodeURIComponent ( key_value [ 1 ] ) : true ; if ( ! obj [ key ] ) { obj [ key ] = val ; } else if ( isArray ( obj [ key ] ) ) { obj [ key ] . push ( val ) ; } else { obj [ key ] = [ obj [ key ] , val ] ; } } } } ) ; return obj ; }


Input: ////////////////////////////////// Module Loading ////////////////////////////////// [CODESPLIT] function loadModules ( modulesToLoad ) { var runBlocks = [ ] ; forEach ( modulesToLoad , function ( module ) { if ( loadedModules . get ( module ) ) return ; loadedModules . put ( module , true ) ; try { if ( isString ( module ) ) { var moduleFn = angularModule ( module ) ; runBlocks = runBlocks . concat ( loadModules ( moduleFn . requires ) ) . concat ( moduleFn . _runBlocks ) ; for ( var invokeQueue = moduleFn . _invokeQueue , i = 0 , ii = invokeQueue . length ; i < ii ; i ++ ) { var invokeArgs = invokeQueue [ i ] , provider = providerInjector . get ( invokeArgs [ 0 ] ) ; provider [ invokeArgs [ 1 ] ] . apply ( provider , invokeArgs [ 2 ] ) ; } } else if ( isFunction ( module ) ) { runBlocks . push ( providerInjector . invoke ( module ) ) ; } else if ( isArray ( module ) ) { runBlocks . push ( providerInjector . invoke ( module ) ) ; } else { assertArgFn ( module , 'module' ) ; } } catch ( e ) { if ( isArray ( module ) ) { module = module [ module . length - 1 ] ; } if ( e . message && e . stack && e . stack . indexOf ( e . message ) == - 1 ) { // Safari & FF's stack traces don't contain error.message content unlike those of Chrome and IE // So if stack doesn't contain message, we create a new string that contains both. // Since error.stack is read-only in Safari, I'm overriding e and not e.stack here. e = e . message + '\n' + e . stack ; } throw $injectorMinErr ( 'modulerr' , "Failed to instantiate module {0} due to:\n{1}" , module , e . stack || e . message || e ) ; } } ) ; return runBlocks ; }


Input: @ngdoc function @name ng . $anchorScroll @requires $window @requires $location @requires $rootScope [CODESPLIT] function $AnchorScrollProvider ( ) { var autoScrollingEnabled = true ; this . disableAutoScrolling = function ( ) { autoScrollingEnabled = false ; } ; this . $get = [ '$window' , '$location' , '$rootScope' , function ( $window , $location , $rootScope ) { var document = $window . document ; // helper function to get first anchor from a NodeList // can't use filter.filter, as it accepts only instances of Array // and IE can't convert NodeList to an array using [].slice // TODO(vojta): use filter if we change it to accept lists as well function getFirstAnchor ( list ) { var result = null ; forEach ( list , function ( element ) { if ( ! result && lowercase ( element . nodeName ) === 'a' ) result = element ; } ) ; return result ; } function scroll ( ) { var hash = $location . hash ( ) , elm ; // empty hash, scroll to the top of the page if ( ! hash ) $window . scrollTo ( 0 , 0 ) ; // element with given id else if ( ( elm = document . getElementById ( hash ) ) ) elm . scrollIntoView ( ) ; // first anchor with given name :-D else if ( ( elm = getFirstAnchor ( document . getElementsByName ( hash ) ) ) ) elm . scrollIntoView ( ) ; // no element and hash == 'top', scroll to the top of the page else if ( hash === 'top' ) $window . scrollTo ( 0 , 0 ) ; } // does not scroll when user clicks on anchor link that is currently on // (no url change, no $location.hash() change), browser native does scroll if ( autoScrollingEnabled ) { $rootScope . $watch ( function autoScrollWatch ( ) { return $location . hash ( ) ; } , function autoScrollWatchAction ( ) { $rootScope . $evalAsync ( scroll ) ; } ) ; } return scroll ; } ] ; }


Input: @ngdoc function @name ng . $animate#enter @methodOf ng . $animate @function [CODESPLIT] function ( element , parent , after , done ) { var afterNode = after && after [ after . length - 1 ] ; var parentNode = parent && parent [ 0 ] || afterNode && afterNode . parentNode ; // IE does not like undefined so we have to pass null. var afterNextSibling = ( afterNode && afterNode . nextSibling ) || null ; forEach ( element , function ( node ) { parentNode . insertBefore ( node , afterNextSibling ) ; } ) ; done && $timeout ( done , 0 , false ) ; }


Input: @ngdoc function @name ng . $animate#addClass @methodOf ng . $animate @function [CODESPLIT] function ( element , className , done ) { className = isString ( className ) ? className : isArray ( className ) ? className . join ( ' ' ) : '' ; forEach ( element , function ( element ) { JQLiteAddClass ( element , className ) ; } ) ; done && $timeout ( done , 0 , false ) ; }