ember-source 4.8.0-alpha.5 → 4.8.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -2
- package/blueprints/helper/files/__root__/{__collection__ → helpers}/__name__.ts +0 -0
- package/blueprints/helper/index.js +0 -15
- package/blueprints/helper-test/index.js +0 -3
- package/blueprints/helper-test/mocha-0.12-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.js +0 -0
- package/blueprints/helper-test/mocha-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.js +0 -0
- package/blueprints/helper-test/mocha-rfc-232-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.ts +0 -0
- package/blueprints/helper-test/qunit-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.js +0 -0
- package/blueprints/helper-test/qunit-rfc-232-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.ts +0 -0
- package/blueprints-js/helper/files/__root__/{__collection__ → helpers}/__name__.js +0 -0
- package/blueprints-js/helper-test/mocha-0.12-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.js +0 -0
- package/blueprints-js/helper-test/mocha-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.js +0 -0
- package/blueprints-js/helper-test/mocha-rfc-232-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.js +0 -0
- package/blueprints-js/helper-test/qunit-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.js +0 -0
- package/blueprints-js/helper-test/qunit-rfc-232-files/__root__/__testType__/{__collection__ → helpers}/__name__-test.js +0 -0
- package/build-metadata.json +3 -3
- package/dist/dependencies/router_js.js +1 -1
- package/dist/ember-template-compiler.js +675 -18
- package/dist/ember-template-compiler.map +1 -1
- package/dist/ember-testing.js +11 -11
- package/dist/ember-testing.map +1 -1
- package/dist/ember.debug.js +19576 -20510
- package/dist/ember.debug.map +1 -1
- package/dist/header/license.js +1 -1
- package/dist/packages/@ember/-internals/glimmer/index.js +4 -2
- package/dist/packages/@ember/-internals/metal/index.js +214 -1094
- package/dist/packages/@ember/-internals/routing/index.js +1 -17
- package/dist/packages/@ember/-internals/runtime/index.js +3 -16
- package/dist/packages/@ember/-internals/runtime/lib/mixins/-proxy.js +2 -1
- package/dist/packages/@ember/-internals/runtime/lib/mixins/action_handler.js +4 -3
- package/dist/packages/@ember/-internals/runtime/lib/mixins/comparable.js +1 -1
- package/dist/packages/@ember/-internals/runtime/lib/mixins/container_proxy.js +1 -1
- package/dist/packages/@ember/-internals/runtime/lib/mixins/registry_proxy.js +1 -8
- package/dist/packages/@ember/-internals/runtime/lib/mixins/target_action_support.js +2 -1
- package/dist/packages/@ember/-internals/utils/index.js +3 -3
- package/dist/packages/@ember/-internals/views/lib/component_lookup.js +1 -1
- package/dist/packages/@ember/-internals/views/lib/mixins/action_support.js +2 -1
- package/dist/packages/@ember/-internals/views/lib/mixins/child_views_support.js +2 -1
- package/dist/packages/@ember/-internals/views/lib/mixins/class_names_support.js +2 -1
- package/dist/packages/@ember/-internals/views/lib/mixins/view_state_support.js +1 -1
- package/dist/packages/@ember/-internals/views/lib/mixins/view_support.js +2 -1
- package/dist/packages/@ember/-internals/views/lib/system/event_dispatcher.js +1 -1
- package/dist/packages/@ember/-internals/views/lib/views/core_view.js +3 -1
- package/dist/packages/@ember/application/index.js +876 -2
- package/dist/packages/@ember/application/instance.js +2 -2
- package/dist/packages/@ember/application/namespace.js +70 -1
- package/dist/packages/@ember/array/index.js +1503 -2
- package/dist/packages/@ember/array/mutable.js +1 -1
- package/dist/packages/@ember/array/proxy.js +307 -1
- package/dist/packages/@ember/canary-features/index.js +2 -2
- package/dist/packages/@ember/controller/index.js +260 -3
- package/dist/packages/@ember/debug/container-debug-adapter.js +99 -1
- package/dist/packages/@ember/debug/data-adapter.js +574 -1
- package/dist/packages/@ember/engine/index.js +5 -5
- package/dist/packages/@ember/engine/instance.js +4 -4
- package/dist/packages/@ember/enumerable/index.js +3 -1
- package/dist/packages/@ember/enumerable/mutable.js +4 -0
- package/dist/packages/@ember/{-internals/runtime/lib/system/object.js → object/-internals.js} +4 -17
- package/dist/packages/@ember/object/core.js +731 -1
- package/dist/packages/@ember/object/evented.js +93 -2
- package/dist/packages/@ember/object/index.js +76 -4
- package/dist/packages/@ember/object/internals.js +3 -2
- package/dist/packages/@ember/object/lib/computed/computed_macros.js +3 -1
- package/dist/packages/@ember/object/lib/computed/reduce_computed_macros.js +4 -3
- package/dist/packages/@ember/object/mixin.js +659 -1
- package/dist/packages/@ember/object/observable.js +341 -1
- package/dist/packages/@ember/object/promise-proxy-mixin.js +150 -1
- package/dist/packages/@ember/object/proxy.js +10 -1
- package/dist/packages/@ember/routing/-internals.js +7 -0
- package/dist/packages/@ember/routing/auto-location.js +249 -1
- package/dist/packages/@ember/routing/hash-location.js +169 -1
- package/dist/packages/@ember/routing/history-location.js +289 -1
- package/dist/packages/@ember/{-internals/routing/lib/system → routing/lib}/cache.js +0 -0
- package/dist/packages/@ember/{-internals/routing/lib/system → routing/lib}/controller_for.js +0 -0
- package/dist/packages/@ember/{-internals/routing/lib/system → routing/lib}/dsl.js +0 -0
- package/dist/packages/@ember/{-internals/routing/lib/system → routing/lib}/engines.js +0 -0
- package/dist/packages/@ember/{-internals/routing/lib/system → routing/lib}/generate_controller.js +0 -0
- package/dist/packages/@ember/{-internals/routing/lib/location/util.js → routing/lib/location-utils.js} +0 -0
- package/dist/packages/@ember/{-internals/routing/lib/system → routing/lib}/query_params.js +0 -0
- package/dist/packages/@ember/{-internals/routing/lib/system → routing/lib}/route-info.js +0 -0
- package/dist/packages/@ember/{-internals/routing/lib/system → routing/lib}/router_state.js +1 -1
- package/dist/packages/@ember/{-internals/routing/lib/services/routing.js → routing/lib/routing-service.js} +2 -2
- package/dist/packages/@ember/{-internals/routing/lib/system → routing/lib}/transition.js +0 -0
- package/dist/packages/@ember/{-internals/routing → routing}/lib/utils.js +0 -0
- package/dist/packages/@ember/routing/location.js +104 -1
- package/dist/packages/@ember/routing/none-location.js +123 -1
- package/dist/packages/@ember/routing/route.js +1700 -1
- package/dist/packages/@ember/routing/router-service.js +510 -1
- package/dist/packages/@ember/routing/router.js +1666 -1
- package/dist/packages/@ember/service/index.js +1 -1
- package/dist/packages/@ember/utils/index.js +7 -2
- package/dist/packages/@ember/{-internals/runtime → utils}/lib/compare.js +2 -2
- package/dist/packages/@ember/{-internals/runtime → utils}/lib/is-equal.js +0 -0
- package/dist/packages/@ember/utils/lib/is_blank.js +35 -0
- package/dist/packages/@ember/utils/lib/is_empty.js +68 -0
- package/dist/packages/@ember/utils/lib/is_none.js +27 -0
- package/dist/packages/@ember/utils/lib/is_present.js +38 -0
- package/dist/packages/@ember/{-internals/runtime → utils}/lib/type-of.js +2 -2
- package/dist/packages/ember/index.js +47 -28
- package/dist/packages/ember/version.js +1 -1
- package/dist/packages/ember-testing/lib/adapters/adapter.js +1 -1
- package/dist/packages/ember-testing/lib/helpers/current_path.js +2 -2
- package/dist/packages/ember-testing/lib/helpers/current_route_name.js +2 -2
- package/dist/packages/ember-testing/lib/helpers/current_url.js +1 -1
- package/docs/data.json +9428 -9189
- package/package.json +23 -8
- package/types/preview/@ember/-internals/resolver.d.ts +35 -0
- package/types/preview/@ember/application/-private/event-dispatcher.d.ts +18 -0
- package/types/preview/@ember/application/-private/registry.d.ts +15 -0
- package/types/preview/@ember/application/deprecations.d.ts +24 -0
- package/types/preview/@ember/application/index.d.ts +153 -0
- package/types/preview/@ember/application/instance.d.ts +9 -0
- package/types/preview/@ember/application/tsconfig.json +3 -0
- package/types/preview/@ember/application/types.d.ts +29 -0
- package/types/preview/@ember/array/-private/enumerable.d.ts +13 -0
- package/types/preview/@ember/array/-private/mutable-enumerable.d.ts +13 -0
- package/types/preview/@ember/array/-private/native-array.d.ts +23 -0
- package/types/preview/@ember/array/index.d.ts +243 -0
- package/types/preview/@ember/array/mutable.d.ts +94 -0
- package/types/preview/@ember/array/proxy.d.ts +29 -0
- package/types/preview/@ember/array/tsconfig.json +3 -0
- package/types/preview/@ember/component/-private/class-names-support.d.ts +27 -0
- package/types/preview/@ember/component/-private/core-view.d.ts +14 -0
- package/types/preview/@ember/component/-private/glimmer-interfaces.d.ts +45 -0
- package/types/preview/@ember/component/-private/signature-utils.d.ts +107 -0
- package/types/preview/@ember/component/-private/view-mixin.d.ts +59 -0
- package/types/preview/@ember/component/helper.d.ts +122 -0
- package/types/preview/@ember/component/index.d.ts +132 -0
- package/types/preview/@ember/component/template-only.d.ts +47 -0
- package/types/preview/@ember/component/tsconfig.json +3 -0
- package/types/preview/@ember/controller/index.d.ts +48 -0
- package/types/preview/@ember/controller/tsconfig.json +3 -0
- package/types/preview/@ember/debug/container-debug-adapter.d.ts +13 -0
- package/types/preview/@ember/debug/data-adapter.d.ts +64 -0
- package/types/preview/@ember/debug/index.d.ts +98 -0
- package/types/preview/@ember/debug/tsconfig.json +3 -0
- package/types/preview/@ember/destroyable/index.d.ts +23 -0
- package/types/preview/@ember/destroyable/tsconfig.json +3 -0
- package/types/preview/@ember/engine/-private/container-proxy-mixin.d.ts +17 -0
- package/types/preview/@ember/engine/-private/registry-proxy-mixin.d.ts +54 -0
- package/types/preview/@ember/engine/-private/types/initializer.d.ts +8 -0
- package/types/preview/@ember/engine/index.d.ts +45 -0
- package/types/preview/@ember/engine/instance.d.ts +24 -0
- package/types/preview/@ember/engine/tsconfig.json +3 -0
- package/types/preview/@ember/error/index.d.ts +6 -0
- package/types/preview/@ember/error/tsconfig.json +3 -0
- package/types/preview/@ember/helper/index.d.ts +49 -0
- package/types/preview/@ember/helper/tsconfig.json +3 -0
- package/types/preview/@ember/modifier/index.d.ts +33 -0
- package/types/preview/@ember/modifier/tsconfig.json +3 -0
- package/types/preview/@ember/object/-private/action-handler.d.ts +31 -0
- package/types/preview/@ember/object/-private/types.d.ts +63 -0
- package/types/preview/@ember/object/compat.d.ts +9 -0
- package/types/preview/@ember/object/computed.d.ts +263 -0
- package/types/preview/@ember/object/core.d.ts +89 -0
- package/types/preview/@ember/object/evented.d.ts +45 -0
- package/types/preview/@ember/object/events.d.ts +47 -0
- package/types/preview/@ember/object/index.d.ts +126 -0
- package/types/preview/@ember/object/internals.d.ts +17 -0
- package/types/preview/@ember/object/mixin.d.ts +19 -0
- package/types/preview/@ember/object/observable.d.ts +89 -0
- package/types/preview/@ember/object/observers.d.ts +34 -0
- package/types/preview/@ember/object/promise-proxy-mixin.d.ts +37 -0
- package/types/preview/@ember/object/proxy.d.ts +27 -0
- package/types/preview/@ember/object/tsconfig.json +3 -0
- package/types/preview/@ember/owner/index.d.ts +102 -0
- package/types/preview/@ember/owner/tsconfig.json +3 -0
- package/types/preview/@ember/polyfills/index.d.ts +23 -0
- package/types/preview/@ember/polyfills/tsconfig.json +3 -0
- package/types/preview/@ember/polyfills/types.d.ts +6 -0
- package/types/preview/@ember/routing/-private/router-dsl.d.ts +20 -0
- package/types/preview/@ember/routing/auto-location.d.ts +8 -0
- package/types/preview/@ember/routing/hash-location.d.ts +10 -0
- package/types/preview/@ember/routing/history-location.d.ts +9 -0
- package/types/preview/@ember/routing/index.d.ts +20 -0
- package/types/preview/@ember/routing/none-location.d.ts +11 -0
- package/types/preview/@ember/routing/route-info.d.ts +74 -0
- package/types/preview/@ember/routing/route.d.ts +533 -0
- package/types/preview/@ember/routing/router-service.d.ts +351 -0
- package/types/preview/@ember/routing/router.d.ts +49 -0
- package/types/preview/@ember/routing/transition.d.ts +126 -0
- package/types/preview/@ember/routing/tsconfig.json +3 -0
- package/types/preview/@ember/routing/types.d.ts +15 -0
- package/types/preview/@ember/runloop/-private/backburner.d.ts +43 -0
- package/types/preview/@ember/runloop/-private/types.d.ts +9 -0
- package/types/preview/@ember/runloop/index.d.ts +175 -0
- package/types/preview/@ember/runloop/tsconfig.json +3 -0
- package/types/preview/@ember/runloop/types.d.ts +5 -0
- package/types/preview/@ember/service/index.d.ts +25 -0
- package/types/preview/@ember/service/tsconfig.json +3 -0
- package/types/preview/@ember/string/index.d.ts +9 -0
- package/types/preview/@ember/string/tsconfig.json +3 -0
- package/types/preview/@ember/template/-private/handlebars.d.ts +7 -0
- package/types/preview/@ember/template/index.d.ts +5 -0
- package/types/preview/@ember/template/tsconfig.json +3 -0
- package/types/preview/@ember/test/adapter.d.ts +22 -0
- package/types/preview/@ember/test/index.d.ts +49 -0
- package/types/preview/@ember/test/tsconfig.json +3 -0
- package/types/preview/@ember/utils/-private/types.d.ts +39 -0
- package/types/preview/@ember/utils/index.d.ts +42 -0
- package/types/preview/@ember/utils/tsconfig.json +3 -0
- package/types/preview/ember/-private/type-utils.d.ts +54 -0
- package/types/preview/ember/index.d.ts +381 -0
- package/types/preview/ember/tsconfig.json +3 -0
- package/types/preview/index.d.ts +120 -0
- package/types/preview/tsconfig.json +6 -0
- package/blueprints/helper/mu-files/__root__/__collection__/__name__.js +0 -7
- package/blueprints-js/helper/mu-files/__root__/__collection__/__name__.js +0 -7
- package/dist/packages/@ember/-internals/extension-support/index.js +0 -2
- package/dist/packages/@ember/-internals/extension-support/lib/container_debug_adapter.js +0 -96
- package/dist/packages/@ember/-internals/extension-support/lib/data_adapter.js +0 -576
- package/dist/packages/@ember/-internals/routing/lib/ext/controller.js +0 -224
- package/dist/packages/@ember/-internals/routing/lib/location/api.js +0 -104
- package/dist/packages/@ember/-internals/routing/lib/location/auto_location.js +0 -250
- package/dist/packages/@ember/-internals/routing/lib/location/hash_location.js +0 -170
- package/dist/packages/@ember/-internals/routing/lib/location/history_location.js +0 -290
- package/dist/packages/@ember/-internals/routing/lib/location/none_location.js +0 -124
- package/dist/packages/@ember/-internals/routing/lib/services/router.js +0 -506
- package/dist/packages/@ember/-internals/routing/lib/system/route.js +0 -1696
- package/dist/packages/@ember/-internals/routing/lib/system/router.js +0 -1662
- package/dist/packages/@ember/-internals/runtime/lib/mixins/array.js +0 -1501
- package/dist/packages/@ember/-internals/runtime/lib/mixins/enumerable.js +0 -3
- package/dist/packages/@ember/-internals/runtime/lib/mixins/evented.js +0 -91
- package/dist/packages/@ember/-internals/runtime/lib/mixins/mutable_enumerable.js +0 -4
- package/dist/packages/@ember/-internals/runtime/lib/mixins/observable.js +0 -339
- package/dist/packages/@ember/-internals/runtime/lib/mixins/promise_proxy.js +0 -149
- package/dist/packages/@ember/-internals/runtime/lib/system/array_proxy.js +0 -305
- package/dist/packages/@ember/-internals/runtime/lib/system/core_object.js +0 -730
- package/dist/packages/@ember/-internals/runtime/lib/system/namespace.js +0 -69
- package/dist/packages/@ember/-internals/runtime/lib/system/object_proxy.js +0 -7
- package/dist/packages/@ember/application/lib/application.js +0 -870
- package/dist/packages/@ember/controller/lib/controller_mixin.js +0 -42
- package/dist/packages/@ember/runloop/type-tests.ts/begin-end.test.js +0 -5
- package/dist/packages/@ember/runloop/type-tests.ts/bind.test.js +0 -59
- package/dist/packages/@ember/runloop/type-tests.ts/cancel.test.js +0 -5
- package/dist/packages/@ember/runloop/type-tests.ts/debounce.test.js +0 -77
- package/dist/packages/@ember/runloop/type-tests.ts/join.test.js +0 -38
- package/dist/packages/@ember/runloop/type-tests.ts/later.test.js +0 -38
- package/dist/packages/@ember/runloop/type-tests.ts/next.test.js +0 -38
- package/dist/packages/@ember/runloop/type-tests.ts/once.test.js +0 -38
- package/dist/packages/@ember/runloop/type-tests.ts/run.test.js +0 -38
- package/dist/packages/@ember/runloop/type-tests.ts/schedule-once.test.js +0 -39
- package/dist/packages/@ember/runloop/type-tests.ts/schedule.test.js +0 -39
- package/dist/packages/@ember/runloop/type-tests.ts/throttle.test.js +0 -77
|
@@ -1 +1,341 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
@module @ember/object/observable
|
|
3
|
+
*/
|
|
4
|
+
import { peekMeta } from '@ember/-internals/meta';
|
|
5
|
+
import { hasListeners, beginPropertyChanges, notifyPropertyChange, endPropertyChanges, addObserver, removeObserver } from '@ember/-internals/metal';
|
|
6
|
+
import { get, set, getProperties, setProperties } from '@ember/object';
|
|
7
|
+
import Mixin from '@ember/object/mixin';
|
|
8
|
+
import { assert } from '@ember/debug';
|
|
9
|
+
const Observable = Mixin.create({
|
|
10
|
+
/**
|
|
11
|
+
Retrieves the value of a property from the object.
|
|
12
|
+
This method is usually similar to using `object[keyName]` or `object.keyName`,
|
|
13
|
+
however it supports both computed properties and the unknownProperty
|
|
14
|
+
handler.
|
|
15
|
+
Because `get` unifies the syntax for accessing all these kinds
|
|
16
|
+
of properties, it can make many refactorings easier, such as replacing a
|
|
17
|
+
simple property with a computed property, or vice versa.
|
|
18
|
+
### Computed Properties
|
|
19
|
+
Computed properties are methods defined with the `property` modifier
|
|
20
|
+
declared at the end, such as:
|
|
21
|
+
```javascript
|
|
22
|
+
import { computed } from '@ember/object';
|
|
23
|
+
fullName: computed('firstName', 'lastName', function() {
|
|
24
|
+
return this.get('firstName') + ' ' + this.get('lastName');
|
|
25
|
+
})
|
|
26
|
+
```
|
|
27
|
+
When you call `get` on a computed property, the function will be
|
|
28
|
+
called and the return value will be returned instead of the function
|
|
29
|
+
itself.
|
|
30
|
+
### Unknown Properties
|
|
31
|
+
Likewise, if you try to call `get` on a property whose value is
|
|
32
|
+
`undefined`, the `unknownProperty()` method will be called on the object.
|
|
33
|
+
If this method returns any value other than `undefined`, it will be returned
|
|
34
|
+
instead. This allows you to implement "virtual" properties that are
|
|
35
|
+
not defined upfront.
|
|
36
|
+
@method get
|
|
37
|
+
@param {String} keyName The property to retrieve
|
|
38
|
+
@return {Object} The property value or undefined.
|
|
39
|
+
@public
|
|
40
|
+
*/
|
|
41
|
+
get(keyName) {
|
|
42
|
+
return get(this, keyName);
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
To get the values of multiple properties at once, call `getProperties`
|
|
47
|
+
with a list of strings or an array:
|
|
48
|
+
```javascript
|
|
49
|
+
record.getProperties('firstName', 'lastName', 'zipCode');
|
|
50
|
+
// { firstName: 'John', lastName: 'Doe', zipCode: '10011' }
|
|
51
|
+
```
|
|
52
|
+
is equivalent to:
|
|
53
|
+
```javascript
|
|
54
|
+
record.getProperties(['firstName', 'lastName', 'zipCode']);
|
|
55
|
+
// { firstName: 'John', lastName: 'Doe', zipCode: '10011' }
|
|
56
|
+
```
|
|
57
|
+
@method getProperties
|
|
58
|
+
@param {String...|Array} list of keys to get
|
|
59
|
+
@return {Object}
|
|
60
|
+
@public
|
|
61
|
+
*/
|
|
62
|
+
getProperties(...args) {
|
|
63
|
+
return getProperties(this, ...args);
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
Sets the provided key or path to the value.
|
|
68
|
+
```javascript
|
|
69
|
+
record.set("key", value);
|
|
70
|
+
```
|
|
71
|
+
This method is generally very similar to calling `object["key"] = value` or
|
|
72
|
+
`object.key = value`, except that it provides support for computed
|
|
73
|
+
properties, the `setUnknownProperty()` method and property observers.
|
|
74
|
+
### Computed Properties
|
|
75
|
+
If you try to set a value on a key that has a computed property handler
|
|
76
|
+
defined (see the `get()` method for an example), then `set()` will call
|
|
77
|
+
that method, passing both the value and key instead of simply changing
|
|
78
|
+
the value itself. This is useful for those times when you need to
|
|
79
|
+
implement a property that is composed of one or more member
|
|
80
|
+
properties.
|
|
81
|
+
### Unknown Properties
|
|
82
|
+
If you try to set a value on a key that is undefined in the target
|
|
83
|
+
object, then the `setUnknownProperty()` handler will be called instead. This
|
|
84
|
+
gives you an opportunity to implement complex "virtual" properties that
|
|
85
|
+
are not predefined on the object. If `setUnknownProperty()` returns
|
|
86
|
+
undefined, then `set()` will simply set the value on the object.
|
|
87
|
+
### Property Observers
|
|
88
|
+
In addition to changing the property, `set()` will also register a property
|
|
89
|
+
change with the object. Unless you have placed this call inside of a
|
|
90
|
+
`beginPropertyChanges()` and `endPropertyChanges(),` any "local" observers
|
|
91
|
+
(i.e. observer methods declared on the same object), will be called
|
|
92
|
+
immediately. Any "remote" observers (i.e. observer methods declared on
|
|
93
|
+
another object) will be placed in a queue and called at a later time in a
|
|
94
|
+
coalesced manner.
|
|
95
|
+
@method set
|
|
96
|
+
@param {String} keyName The property to set
|
|
97
|
+
@param {Object} value The value to set or `null`.
|
|
98
|
+
@return {Object} The passed value
|
|
99
|
+
@public
|
|
100
|
+
*/
|
|
101
|
+
set(keyName, value) {
|
|
102
|
+
return set(this, keyName, value);
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
Sets a list of properties at once. These properties are set inside
|
|
107
|
+
a single `beginPropertyChanges` and `endPropertyChanges` batch, so
|
|
108
|
+
observers will be buffered.
|
|
109
|
+
```javascript
|
|
110
|
+
record.setProperties({ firstName: 'Charles', lastName: 'Jolley' });
|
|
111
|
+
```
|
|
112
|
+
@method setProperties
|
|
113
|
+
@param {Object} hash the hash of keys and values to set
|
|
114
|
+
@return {Object} The passed in hash
|
|
115
|
+
@public
|
|
116
|
+
*/
|
|
117
|
+
setProperties(hash) {
|
|
118
|
+
return setProperties(this, hash);
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
Begins a grouping of property changes.
|
|
123
|
+
You can use this method to group property changes so that notifications
|
|
124
|
+
will not be sent until the changes are finished. If you plan to make a
|
|
125
|
+
large number of changes to an object at one time, you should call this
|
|
126
|
+
method at the beginning of the changes to begin deferring change
|
|
127
|
+
notifications. When you are done making changes, call
|
|
128
|
+
`endPropertyChanges()` to deliver the deferred change notifications and end
|
|
129
|
+
deferring.
|
|
130
|
+
@method beginPropertyChanges
|
|
131
|
+
@return {Observable}
|
|
132
|
+
@private
|
|
133
|
+
*/
|
|
134
|
+
beginPropertyChanges() {
|
|
135
|
+
beginPropertyChanges();
|
|
136
|
+
return this;
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
Ends a grouping of property changes.
|
|
141
|
+
You can use this method to group property changes so that notifications
|
|
142
|
+
will not be sent until the changes are finished. If you plan to make a
|
|
143
|
+
large number of changes to an object at one time, you should call
|
|
144
|
+
`beginPropertyChanges()` at the beginning of the changes to defer change
|
|
145
|
+
notifications. When you are done making changes, call this method to
|
|
146
|
+
deliver the deferred change notifications and end deferring.
|
|
147
|
+
@method endPropertyChanges
|
|
148
|
+
@return {Observable}
|
|
149
|
+
@private
|
|
150
|
+
*/
|
|
151
|
+
endPropertyChanges() {
|
|
152
|
+
endPropertyChanges();
|
|
153
|
+
return this;
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
Notify the observer system that a property has just changed.
|
|
158
|
+
Sometimes you need to change a value directly or indirectly without
|
|
159
|
+
actually calling `get()` or `set()` on it. In this case, you can use this
|
|
160
|
+
method instead. Calling this method will notify all observers that the
|
|
161
|
+
property has potentially changed value.
|
|
162
|
+
@method notifyPropertyChange
|
|
163
|
+
@param {String} keyName The property key to be notified about.
|
|
164
|
+
@return {Observable}
|
|
165
|
+
@public
|
|
166
|
+
*/
|
|
167
|
+
notifyPropertyChange(keyName) {
|
|
168
|
+
notifyPropertyChange(this, keyName);
|
|
169
|
+
return this;
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
Adds an observer on a property.
|
|
174
|
+
This is the core method used to register an observer for a property.
|
|
175
|
+
Once you call this method, any time the key's value is set, your observer
|
|
176
|
+
will be notified. Note that the observers are triggered any time the
|
|
177
|
+
value is set, regardless of whether it has actually changed. Your
|
|
178
|
+
observer should be prepared to handle that.
|
|
179
|
+
There are two common invocation patterns for `.addObserver()`:
|
|
180
|
+
- Passing two arguments:
|
|
181
|
+
- the name of the property to observe (as a string)
|
|
182
|
+
- the function to invoke (an actual function)
|
|
183
|
+
- Passing three arguments:
|
|
184
|
+
- the name of the property to observe (as a string)
|
|
185
|
+
- the target object (will be used to look up and invoke a
|
|
186
|
+
function on)
|
|
187
|
+
- the name of the function to invoke on the target object
|
|
188
|
+
(as a string).
|
|
189
|
+
```app/components/my-component.js
|
|
190
|
+
import Component from '@ember/component';
|
|
191
|
+
export default Component.extend({
|
|
192
|
+
init() {
|
|
193
|
+
this._super(...arguments);
|
|
194
|
+
// the following are equivalent:
|
|
195
|
+
// using three arguments
|
|
196
|
+
this.addObserver('foo', this, 'fooDidChange');
|
|
197
|
+
// using two arguments
|
|
198
|
+
this.addObserver('foo', (...args) => {
|
|
199
|
+
this.fooDidChange(...args);
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
fooDidChange() {
|
|
203
|
+
// your custom logic code
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
### Observer Methods
|
|
208
|
+
Observer methods have the following signature:
|
|
209
|
+
```app/components/my-component.js
|
|
210
|
+
import Component from '@ember/component';
|
|
211
|
+
export default Component.extend({
|
|
212
|
+
init() {
|
|
213
|
+
this._super(...arguments);
|
|
214
|
+
this.addObserver('foo', this, 'fooDidChange');
|
|
215
|
+
},
|
|
216
|
+
fooDidChange(sender, key, value, rev) {
|
|
217
|
+
// your code
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
```
|
|
221
|
+
The `sender` is the object that changed. The `key` is the property that
|
|
222
|
+
changes. The `value` property is currently reserved and unused. The `rev`
|
|
223
|
+
is the last property revision of the object when it changed, which you can
|
|
224
|
+
use to detect if the key value has really changed or not.
|
|
225
|
+
Usually you will not need the value or revision parameters at
|
|
226
|
+
the end. In this case, it is common to write observer methods that take
|
|
227
|
+
only a sender and key value as parameters or, if you aren't interested in
|
|
228
|
+
any of these values, to write an observer that has no parameters at all.
|
|
229
|
+
@method addObserver
|
|
230
|
+
@param {String} key The key to observe
|
|
231
|
+
@param {Object} target The target object to invoke
|
|
232
|
+
@param {String|Function} method The method to invoke
|
|
233
|
+
@param {Boolean} sync Whether the observer is sync or not
|
|
234
|
+
@return {Observable}
|
|
235
|
+
@public
|
|
236
|
+
*/
|
|
237
|
+
addObserver(key, target, method, sync) {
|
|
238
|
+
addObserver(this, key, target, method, sync);
|
|
239
|
+
return this;
|
|
240
|
+
},
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
Remove an observer you have previously registered on this object. Pass
|
|
244
|
+
the same key, target, and method you passed to `addObserver()` and your
|
|
245
|
+
target will no longer receive notifications.
|
|
246
|
+
@method removeObserver
|
|
247
|
+
@param {String} key The key to observe
|
|
248
|
+
@param {Object} target The target object to invoke
|
|
249
|
+
@param {String|Function} method The method to invoke
|
|
250
|
+
@param {Boolean} sync Whether the observer is async or not
|
|
251
|
+
@return {Observable}
|
|
252
|
+
@public
|
|
253
|
+
*/
|
|
254
|
+
removeObserver(key, target, method, sync) {
|
|
255
|
+
removeObserver(this, key, target, method, sync);
|
|
256
|
+
return this;
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
Returns `true` if the object currently has observers registered for a
|
|
261
|
+
particular key. You can use this method to potentially defer performing
|
|
262
|
+
an expensive action until someone begins observing a particular property
|
|
263
|
+
on the object.
|
|
264
|
+
@method hasObserverFor
|
|
265
|
+
@param {String} key Key to check
|
|
266
|
+
@return {Boolean}
|
|
267
|
+
@private
|
|
268
|
+
*/
|
|
269
|
+
hasObserverFor(key) {
|
|
270
|
+
return hasListeners(this, `${key}:change`);
|
|
271
|
+
},
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
Set the value of a property to the current value plus some amount.
|
|
275
|
+
```javascript
|
|
276
|
+
person.incrementProperty('age');
|
|
277
|
+
team.incrementProperty('score', 2);
|
|
278
|
+
```
|
|
279
|
+
@method incrementProperty
|
|
280
|
+
@param {String} keyName The name of the property to increment
|
|
281
|
+
@param {Number} increment The amount to increment by. Defaults to 1
|
|
282
|
+
@return {Number} The new property value
|
|
283
|
+
@public
|
|
284
|
+
*/
|
|
285
|
+
incrementProperty(keyName, increment = 1) {
|
|
286
|
+
assert('Must pass a numeric value to incrementProperty', !isNaN(parseFloat(String(increment))) && isFinite(increment));
|
|
287
|
+
return set(this, keyName, (parseFloat(get(this, keyName)) || 0) + increment);
|
|
288
|
+
},
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
Set the value of a property to the current value minus some amount.
|
|
292
|
+
```javascript
|
|
293
|
+
player.decrementProperty('lives');
|
|
294
|
+
orc.decrementProperty('health', 5);
|
|
295
|
+
```
|
|
296
|
+
@method decrementProperty
|
|
297
|
+
@param {String} keyName The name of the property to decrement
|
|
298
|
+
@param {Number} decrement The amount to decrement by. Defaults to 1
|
|
299
|
+
@return {Number} The new property value
|
|
300
|
+
@public
|
|
301
|
+
*/
|
|
302
|
+
decrementProperty(keyName, decrement = 1) {
|
|
303
|
+
assert('Must pass a numeric value to decrementProperty', (typeof decrement === 'number' || !isNaN(parseFloat(decrement))) && isFinite(decrement));
|
|
304
|
+
return set(this, keyName, (get(this, keyName) || 0) - decrement);
|
|
305
|
+
},
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
Set the value of a boolean property to the opposite of its
|
|
309
|
+
current value.
|
|
310
|
+
```javascript
|
|
311
|
+
starship.toggleProperty('warpDriveEngaged');
|
|
312
|
+
```
|
|
313
|
+
@method toggleProperty
|
|
314
|
+
@param {String} keyName The name of the property to toggle
|
|
315
|
+
@return {Boolean} The new property value
|
|
316
|
+
@public
|
|
317
|
+
*/
|
|
318
|
+
toggleProperty(keyName) {
|
|
319
|
+
return set(this, keyName, !get(this, keyName));
|
|
320
|
+
},
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
Returns the cached value of a computed property, if it exists.
|
|
324
|
+
This allows you to inspect the value of a computed property
|
|
325
|
+
without accidentally invoking it if it is intended to be
|
|
326
|
+
generated lazily.
|
|
327
|
+
@method cacheFor
|
|
328
|
+
@param {String} keyName
|
|
329
|
+
@return {Object} The cached value of the computed property, if any
|
|
330
|
+
@public
|
|
331
|
+
*/
|
|
332
|
+
cacheFor(keyName) {
|
|
333
|
+
let meta = peekMeta(this);
|
|
334
|
+
|
|
335
|
+
if (meta !== null) {
|
|
336
|
+
return meta.valueFor(keyName);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
});
|
|
341
|
+
export default Observable;
|
|
@@ -1 +1,150 @@
|
|
|
1
|
-
|
|
1
|
+
import { get, setProperties, computed } from '@ember/object';
|
|
2
|
+
import Mixin from '@ember/object/mixin';
|
|
3
|
+
import EmberError from '@ember/error';
|
|
4
|
+
/**
|
|
5
|
+
@module @ember/object/promise-proxy-mixin
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
function tap(proxy, promise) {
|
|
9
|
+
setProperties(proxy, {
|
|
10
|
+
isFulfilled: false,
|
|
11
|
+
isRejected: false
|
|
12
|
+
});
|
|
13
|
+
return promise.then(value => {
|
|
14
|
+
if (!proxy.isDestroyed && !proxy.isDestroying) {
|
|
15
|
+
setProperties(proxy, {
|
|
16
|
+
content: value,
|
|
17
|
+
isFulfilled: true
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return value;
|
|
22
|
+
}, reason => {
|
|
23
|
+
if (!proxy.isDestroyed && !proxy.isDestroying) {
|
|
24
|
+
setProperties(proxy, {
|
|
25
|
+
reason,
|
|
26
|
+
isRejected: true
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
throw reason;
|
|
31
|
+
}, 'Ember: PromiseProxy');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const PromiseProxyMixin = Mixin.create({
|
|
35
|
+
/**
|
|
36
|
+
If the proxied promise is rejected this will contain the reason
|
|
37
|
+
provided.
|
|
38
|
+
@property reason
|
|
39
|
+
@default null
|
|
40
|
+
@public
|
|
41
|
+
*/
|
|
42
|
+
reason: null,
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
Once the proxied promise has settled this will become `false`.
|
|
46
|
+
@property isPending
|
|
47
|
+
@default true
|
|
48
|
+
@public
|
|
49
|
+
*/
|
|
50
|
+
isPending: computed('isSettled', function () {
|
|
51
|
+
return !get(this, 'isSettled');
|
|
52
|
+
}).readOnly(),
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
Once the proxied promise has settled this will become `true`.
|
|
56
|
+
@property isSettled
|
|
57
|
+
@default false
|
|
58
|
+
@public
|
|
59
|
+
*/
|
|
60
|
+
isSettled: computed('isRejected', 'isFulfilled', function () {
|
|
61
|
+
return get(this, 'isRejected') || get(this, 'isFulfilled');
|
|
62
|
+
}).readOnly(),
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
Will become `true` if the proxied promise is rejected.
|
|
66
|
+
@property isRejected
|
|
67
|
+
@default false
|
|
68
|
+
@public
|
|
69
|
+
*/
|
|
70
|
+
isRejected: false,
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
Will become `true` if the proxied promise is fulfilled.
|
|
74
|
+
@property isFulfilled
|
|
75
|
+
@default false
|
|
76
|
+
@public
|
|
77
|
+
*/
|
|
78
|
+
isFulfilled: false,
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
The promise whose fulfillment value is being proxied by this object.
|
|
82
|
+
This property must be specified upon creation, and should not be
|
|
83
|
+
changed once created.
|
|
84
|
+
Example:
|
|
85
|
+
```javascript
|
|
86
|
+
import ObjectProxy from '@ember/object/proxy';
|
|
87
|
+
import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
|
|
88
|
+
ObjectProxy.extend(PromiseProxyMixin).create({
|
|
89
|
+
promise: <thenable>
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
@property promise
|
|
93
|
+
@public
|
|
94
|
+
*/
|
|
95
|
+
promise: computed({
|
|
96
|
+
get() {
|
|
97
|
+
throw new EmberError("PromiseProxy's promise must be set");
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
set(_key, promise) {
|
|
101
|
+
return tap(this, promise);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
}),
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
An alias to the proxied promise's `then`.
|
|
108
|
+
See RSVP.Promise.then.
|
|
109
|
+
@method then
|
|
110
|
+
@param {Function} callback
|
|
111
|
+
@return {RSVP.Promise}
|
|
112
|
+
@public
|
|
113
|
+
*/
|
|
114
|
+
then: promiseAlias('then'),
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
An alias to the proxied promise's `catch`.
|
|
118
|
+
See RSVP.Promise.catch.
|
|
119
|
+
@method catch
|
|
120
|
+
@param {Function} callback
|
|
121
|
+
@return {RSVP.Promise}
|
|
122
|
+
@since 1.3.0
|
|
123
|
+
@public
|
|
124
|
+
*/
|
|
125
|
+
catch: promiseAlias('catch'),
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
An alias to the proxied promise's `finally`.
|
|
129
|
+
See RSVP.Promise.finally.
|
|
130
|
+
@method finally
|
|
131
|
+
@param {Function} callback
|
|
132
|
+
@return {RSVP.Promise}
|
|
133
|
+
@since 1.3.0
|
|
134
|
+
@public
|
|
135
|
+
*/
|
|
136
|
+
finally: promiseAlias('finally')
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
function promiseAlias(name) {
|
|
140
|
+
return function (...args) {
|
|
141
|
+
let promise = get(this, 'promise'); // We need this cast because `Parameters` is deferred so that it is not
|
|
142
|
+
// possible for TS to see it will always produce the right type. However,
|
|
143
|
+
// since `AnyFn` has a rest type, it is allowed. See discussion on [this
|
|
144
|
+
// issue](https://github.com/microsoft/TypeScript/issues/47615).
|
|
145
|
+
|
|
146
|
+
return promise[name](...args);
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export default PromiseProxyMixin;
|
|
@@ -1 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
@module @ember/object/proxy
|
|
3
|
+
*/
|
|
4
|
+
import { FrameworkObject } from '@ember/object/-internals';
|
|
5
|
+
import { _ProxyMixin } from '@ember/-internals/runtime';
|
|
6
|
+
|
|
7
|
+
class ObjectProxy extends FrameworkObject {}
|
|
8
|
+
|
|
9
|
+
ObjectProxy.PrototypeMixin.reopen(_ProxyMixin);
|
|
10
|
+
export default ObjectProxy;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as RouterState } from './lib/router_state';
|
|
2
|
+
export { default as RoutingService } from './lib/routing-service';
|
|
3
|
+
export { deprecateTransitionMethods, prefixRouteNameArg } from './lib/utils';
|
|
4
|
+
export { default as generateController, generateControllerFactory } from './lib/generate_controller';
|
|
5
|
+
export { default as BucketCache } from './lib/cache';
|
|
6
|
+
export { default as DSL } from './lib/dsl';
|
|
7
|
+
export { default as controllerFor } from './lib/controller_for';
|