-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
Copy pathcopyable.js
70 lines (59 loc) · 1.9 KB
/
copyable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
@module ember
*/
import {
get,
Mixin
} from 'ember-metal';
import { deprecate, Error as EmberError } from 'ember-debug';
import { Freezable } from './freezable';
/**
Implements some standard methods for copying an object. Add this mixin to
any object you create that can create a copy of itself. This mixin is
added automatically to the built-in array.
You should generally implement the `copy()` method to return a copy of the
receiver.
Note that `frozenCopy()` will only work if you also implement
`Ember.Freezable`.
@class Copyable
@namespace Ember
@since Ember 0.9
@private
*/
export default Mixin.create({
/**
__Required.__ You must implement this method to apply this mixin.
Override to return a copy of the receiver. Default implementation raises
an exception.
@method copy
@param {Boolean} deep if `true`, a deep copy of the object should be made
@return {Object} copy of receiver
@private
*/
copy: null,
/**
If the object implements `Ember.Freezable`, then this will return a new
copy if the object is not frozen and the receiver if the object is frozen.
Raises an exception if you try to call this method on a object that does
not support freezing.
You should use this method whenever you want a copy of a freezable object
since a freezable object can simply return itself without actually
consuming more memory.
@method frozenCopy
@return {Object} copy of receiver or receiver
@deprecated Use `Object.freeze` instead.
@private
*/
frozenCopy() {
deprecate(
'`frozenCopy` is deprecated, use `Object.freeze` instead.',
false,
{ id: 'ember-runtime.frozen-copy', until: '3.0.0' }
);
if (Freezable && Freezable.detect(this)) {
return get(this, 'isFrozen') ? this : this.copy().freeze();
} else {
throw new EmberError(`${this} does not support freezing`);
}
}
});