@@ -3891,7 +3891,7 @@ function DSProvider() {
3891
3891
3892
3892
module . exports = DSProvider ;
3893
3893
3894
- } , { "../utils" :62 , "./async_methods" :38 , "./sync_methods" :55 } ] , 45 :[ function ( require , module , exports ) {
3894
+ } , { "../utils" :63 , "./async_methods" :38 , "./sync_methods" :56 } ] , 45 :[ function ( require , module , exports ) {
3895
3895
var errorPrefix = 'DS.bindAll(scope, expr, resourceName, params[, cb]): ' ;
3896
3896
3897
3897
/**
@@ -4096,6 +4096,76 @@ function changes(resourceName, id) {
4096
4096
module . exports = changes ;
4097
4097
4098
4098
} , { } ] , 48 :[ function ( require , module , exports ) {
4099
+ var errorPrefix = 'DS.createInstance(resourceName[, attrs][, options]): ' ;
4100
+
4101
+ /**
4102
+ * @doc method
4103
+ * @id DS.sync_methods:createInstance
4104
+ * @name createInstance
4105
+ * @description
4106
+ * Return a new instance of the specified resource.
4107
+ *
4108
+ * ## Signature:
4109
+ * ```js
4110
+ * DS.createInstance(resourceName[, attrs][, options])
4111
+ * ```
4112
+ *
4113
+ * ## Example:
4114
+ *
4115
+ * ```js
4116
+ * // Thanks to createInstance, you don't have to do this anymore
4117
+ * var User = DS.definitions.user[DS.definitions.user.class];
4118
+ *
4119
+ * var user = DS.createInstance('user');
4120
+ *
4121
+ * user instanceof User; // true
4122
+ * ```
4123
+ *
4124
+ * ## Throws
4125
+ *
4126
+ * - `{IllegalArgumentError}`
4127
+ * - `{NonexistentResourceError}`
4128
+ *
4129
+ * @param {string } resourceName The resource type, e.g. 'user', 'comment', etc.
4130
+ * @param {object= } attrs Optional attributes to mix in to the new instance.
4131
+ * @param {object= } options Optional configuration. Properties:
4132
+ *
4133
+ * - `{boolean=}` - `useClass` - Whether to use the resource's wrapper class. Default: `true`.
4134
+ *
4135
+ * @returns {object } The new instance
4136
+ */
4137
+ function createInstance ( resourceName , attrs , options ) {
4138
+ var IA = this . errors . IA ;
4139
+
4140
+ attrs = attrs || { } ;
4141
+ options = options || { } ;
4142
+
4143
+ if ( ! this . definitions [ resourceName ] ) {
4144
+ throw new this . errors . NER ( errorPrefix + resourceName ) ;
4145
+ } else if ( attrs && ! this . utils . isObject ( attrs ) ) {
4146
+ throw new IA ( errorPrefix + 'attrs: Must be an object!' ) ;
4147
+ } else if ( ! this . utils . isObject ( options ) ) {
4148
+ throw new IA ( errorPrefix + 'options: Must be an object!' ) ;
4149
+ }
4150
+
4151
+ if ( ! ( 'useClass' in options ) ) {
4152
+ options . useClass = true ;
4153
+ }
4154
+
4155
+ var item ;
4156
+
4157
+ if ( options . useClass ) {
4158
+ var Func = this . definitions [ resourceName ] [ this . definitions [ resourceName ] . class ] ;
4159
+ item = new Func ( ) ;
4160
+ } else {
4161
+ item = { } ;
4162
+ }
4163
+ return this . utils . deepMixIn ( item , attrs ) ;
4164
+ }
4165
+
4166
+ module . exports = createInstance ;
4167
+
4168
+ } , { } ] , 49 :[ function ( require , module , exports ) {
4099
4169
/*jshint evil:true*/
4100
4170
var errorPrefix = 'DS.defineResource(definition): ' ;
4101
4171
@@ -4259,7 +4329,7 @@ function defineResource(definition) {
4259
4329
4260
4330
module . exports = defineResource ;
4261
4331
4262
- } , { } ] , 49 :[ function ( require , module , exports ) {
4332
+ } , { } ] , 50 :[ function ( require , module , exports ) {
4263
4333
var observe = require ( '../../../lib/observe-js/observe-js' ) ;
4264
4334
4265
4335
/**
@@ -4294,7 +4364,7 @@ function digest() {
4294
4364
4295
4365
module . exports = digest ;
4296
4366
4297
- } , { "../../../lib/observe-js/observe-js" :1 } ] , 50 :[ function ( require , module , exports ) {
4367
+ } , { "../../../lib/observe-js/observe-js" :1 } ] , 51 :[ function ( require , module , exports ) {
4298
4368
var errorPrefix = 'DS.eject(resourceName, id): ' ;
4299
4369
4300
4370
function _eject ( definition , resource , id ) {
@@ -4372,7 +4442,7 @@ function eject(resourceName, id) {
4372
4442
4373
4443
module . exports = eject ;
4374
4444
4375
- } , { } ] , 51 :[ function ( require , module , exports ) {
4445
+ } , { } ] , 52 :[ function ( require , module , exports ) {
4376
4446
var errorPrefix = 'DS.ejectAll(resourceName[, params]): ' ;
4377
4447
4378
4448
function _ejectAll ( definition , resource , params ) {
@@ -4480,7 +4550,7 @@ function ejectAll(resourceName, params) {
4480
4550
4481
4551
module . exports = ejectAll ;
4482
4552
4483
- } , { } ] , 52 :[ function ( require , module , exports ) {
4553
+ } , { } ] , 53 :[ function ( require , module , exports ) {
4484
4554
var errorPrefix = 'DS.filter(resourceName[, params][, options]): ' ;
4485
4555
4486
4556
/**
@@ -4561,7 +4631,7 @@ function filter(resourceName, params, options) {
4561
4631
4562
4632
module . exports = filter ;
4563
4633
4564
- } , { } ] , 53 :[ function ( require , module , exports ) {
4634
+ } , { } ] , 54 :[ function ( require , module , exports ) {
4565
4635
var errorPrefix = 'DS.get(resourceName, id[, options]): ' ;
4566
4636
4567
4637
/**
@@ -4591,7 +4661,9 @@ var errorPrefix = 'DS.get(resourceName, id[, options]): ';
4591
4661
* @param {string } resourceName The resource type, e.g. 'user', 'comment', etc.
4592
4662
* @param {string|number } id The primary key of the item to retrieve.
4593
4663
* @param {object= } options Optional configuration. Properties:
4664
+ *
4594
4665
* - `{boolean=}` - `loadFromServer` - Send the query to server if it has not been sent yet. Default: `false`.
4666
+ *
4595
4667
* @returns {object } The item of the type specified by `resourceName` with the primary key specified by `id`.
4596
4668
*/
4597
4669
function get ( resourceName , id , options ) {
@@ -4622,7 +4694,7 @@ function get(resourceName, id, options) {
4622
4694
4623
4695
module . exports = get ;
4624
4696
4625
- } , { } ] , 54 :[ function ( require , module , exports ) {
4697
+ } , { } ] , 55 :[ function ( require , module , exports ) {
4626
4698
var errorPrefix = 'DS.hasChanges(resourceName, id): ' ;
4627
4699
4628
4700
function diffIsEmpty ( utils , diff ) {
@@ -4680,17 +4752,8 @@ function hasChanges(resourceName, id) {
4680
4752
4681
4753
module . exports = hasChanges ;
4682
4754
4683
- } , { } ] , 55 :[ function ( require , module , exports ) {
4755
+ } , { } ] , 56 :[ function ( require , module , exports ) {
4684
4756
module . exports = {
4685
- /**
4686
- * @doc method
4687
- * @id DS.sync_methods:defineResource
4688
- * @name defineResource
4689
- * @methodOf DS
4690
- * @description
4691
- * See [DS.defineResource](/documentation/api/api/DS.sync_methods:defineResource).
4692
- */
4693
- defineResource : require ( './defineResource' ) ,
4694
4757
4695
4758
/**
4696
4759
* @doc method
@@ -4712,6 +4775,26 @@ module.exports = {
4712
4775
*/
4713
4776
bindAll : require ( './bindAll' ) ,
4714
4777
4778
+ /**
4779
+ * @doc method
4780
+ * @id DS.sync_methods:createInstance
4781
+ * @name createInstance
4782
+ * @methodOf DS
4783
+ * @description
4784
+ * See [DS.createInstance](/documentation/api/api/DS.sync_methods:createInstance).
4785
+ */
4786
+ createInstance : require ( './createInstance' ) ,
4787
+
4788
+ /**
4789
+ * @doc method
4790
+ * @id DS.sync_methods:defineResource
4791
+ * @name defineResource
4792
+ * @methodOf DS
4793
+ * @description
4794
+ * See [DS.defineResource](/documentation/api/api/DS.sync_methods:defineResource).
4795
+ */
4796
+ defineResource : require ( './defineResource' ) ,
4797
+
4715
4798
/**
4716
4799
* @doc method
4717
4800
* @id DS.sync_methods:eject
@@ -4823,7 +4906,7 @@ module.exports = {
4823
4906
hasChanges : require ( './hasChanges' )
4824
4907
} ;
4825
4908
4826
- } , { "./bindAll" :45 , "./bindOne" :46 , "./changes" :47 , "./defineResource " :48 , "./digest " :49 , "./eject " :50 , "./ejectAll " :51 , "./filter " :52 , "./get " :53 , "./hasChanges " :54 , "./inject" :56 , "./lastModified" :57 , "./lastSaved" :58 , "./previous" :59 } ] , 56 :[ function ( require , module , exports ) {
4909
+ } , { "./bindAll" :45 , "./bindOne" :46 , "./changes" :47 , "./createInstance " :48 , "./defineResource " :49 , "./digest " :50 , "./eject " :51 , "./ejectAll " :52 , "./filter " :53 , "./get " :54 , "./hasChanges" : 55 , "./ inject" :57 , "./lastModified" :58 , "./lastSaved" :59 , "./previous" :60 } ] , 57 :[ function ( require , module , exports ) {
4827
4910
var observe = require ( '../../../lib/observe-js/observe-js' ) ;
4828
4911
var errorPrefix = 'DS.inject(resourceName, attrs[, options]): ' ;
4829
4912
@@ -5026,7 +5109,7 @@ function inject(resourceName, attrs, options) {
5026
5109
5027
5110
module . exports = inject ;
5028
5111
5029
- } , { "../../../lib/observe-js/observe-js" :1 } ] , 57 :[ function ( require , module , exports ) {
5112
+ } , { "../../../lib/observe-js/observe-js" :1 } ] , 58 :[ function ( require , module , exports ) {
5030
5113
var errorPrefix = 'DS.lastModified(resourceName[, id]): ' ;
5031
5114
5032
5115
/**
@@ -5079,7 +5162,7 @@ function lastModified(resourceName, id) {
5079
5162
5080
5163
module . exports = lastModified ;
5081
5164
5082
- } , { } ] , 58 :[ function ( require , module , exports ) {
5165
+ } , { } ] , 59 :[ function ( require , module , exports ) {
5083
5166
var errorPrefix = 'DS.lastSaved(resourceName[, id]): ' ;
5084
5167
5085
5168
/**
@@ -5135,7 +5218,7 @@ function lastSaved(resourceName, id) {
5135
5218
5136
5219
module . exports = lastSaved ;
5137
5220
5138
- } , { } ] , 59 :[ function ( require , module , exports ) {
5221
+ } , { } ] , 60 :[ function ( require , module , exports ) {
5139
5222
var errorPrefix = 'DS.previous(resourceName, id): ' ;
5140
5223
5141
5224
/**
@@ -5185,7 +5268,7 @@ function previous(resourceName, id) {
5185
5268
5186
5269
module . exports = previous ;
5187
5270
5188
- } , { } ] , 60 :[ function ( require , module , exports ) {
5271
+ } , { } ] , 61 :[ function ( require , module , exports ) {
5189
5272
/**
5190
5273
* @doc function
5191
5274
* @id errors.types:IllegalArgumentError
@@ -5318,7 +5401,7 @@ module.exports = [function () {
5318
5401
} ;
5319
5402
} ] ;
5320
5403
5321
- } , { } ] , 61 :[ function ( require , module , exports ) {
5404
+ } , { } ] , 62 :[ function ( require , module , exports ) {
5322
5405
( function ( window , angular , undefined ) {
5323
5406
'use strict' ;
5324
5407
@@ -5401,7 +5484,7 @@ module.exports = [function () {
5401
5484
5402
5485
} ) ( window , window . angular ) ;
5403
5486
5404
- } , { "./adapters/http" :31 , "./adapters/localStorage" :32 , "./datastore" :44 , "./errors" :60 , "./utils" :62 } ] , 62 :[ function ( require , module , exports ) {
5487
+ } , { "./adapters/http" :31 , "./adapters/localStorage" :32 , "./datastore" :44 , "./errors" :61 , "./utils" :63 } ] , 63 :[ function ( require , module , exports ) {
5405
5488
module . exports = [ function ( ) {
5406
5489
return {
5407
5490
isBoolean : require ( 'mout/lang/isBoolean' ) ,
@@ -5484,4 +5567,4 @@ module.exports = [function () {
5484
5567
} ;
5485
5568
} ] ;
5486
5569
5487
- } , { "mout/array/contains" :2 , "mout/array/filter" :3 , "mout/array/slice" :7 , "mout/array/sort" :8 , "mout/array/toLookup" :9 , "mout/lang/isBoolean" :14 , "mout/lang/isEmpty" :15 , "mout/object/deepMixIn" :22 , "mout/object/forOwn" :24 , "mout/object/pick" :27 , "mout/object/set" :28 , "mout/string/makePath" :29 , "mout/string/upperCase" :30 } ] } , { } , [ 61 ] ) ;
5570
+ } , { "mout/array/contains" :2 , "mout/array/filter" :3 , "mout/array/slice" :7 , "mout/array/sort" :8 , "mout/array/toLookup" :9 , "mout/lang/isBoolean" :14 , "mout/lang/isEmpty" :15 , "mout/object/deepMixIn" :22 , "mout/object/forOwn" :24 , "mout/object/pick" :27 , "mout/object/set" :28 , "mout/string/makePath" :29 , "mout/string/upperCase" :30 } ] } , { } , [ 62 ] ) ;
0 commit comments