ember-source 7.1.0-alpha.3 → 7.1.0-alpha.5
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/build-metadata.json +3 -3
- package/dist/dev/packages/@ember/-internals/container/index.js +4 -401
- package/dist/dev/packages/@ember/-internals/deprecations/index.js +1 -1
- package/dist/dev/packages/@ember/-internals/environment/index.js +3 -151
- package/dist/dev/packages/@ember/-internals/glimmer/index.js +14 -15
- package/dist/dev/packages/@ember/-internals/meta/lib/meta.js +0 -1
- package/dist/dev/packages/@ember/-internals/metal/index.js +18 -9
- package/dist/dev/packages/@ember/-internals/routing/index.js +1 -10
- package/dist/dev/packages/@ember/-internals/runtime/lib/mixins/-proxy.js +10 -12
- package/dist/dev/packages/@ember/-internals/runtime/lib/mixins/action_handler.js +1 -10
- package/dist/dev/packages/@ember/-internals/runtime/lib/mixins/target_action_support.js +3 -10
- package/dist/dev/packages/@ember/-internals/string/index.js +0 -1
- package/dist/dev/packages/@ember/-internals/utils/index.js +8 -3
- package/dist/dev/packages/@ember/-internals/views/lib/compat/fallback-view-registry.js +0 -1
- package/dist/dev/packages/@ember/-internals/views/lib/mixins/action_support.js +3 -12
- package/dist/dev/packages/@ember/-internals/views/lib/system/event_dispatcher.js +2 -11
- package/dist/dev/packages/@ember/-internals/views/lib/system/utils.js +1 -1
- package/dist/dev/packages/@ember/-internals/views/lib/views/core_view.js +1 -18
- package/dist/dev/packages/@ember/-internals/views/lib/views/states.js +1 -1
- package/dist/dev/packages/@ember/application/index.js +5 -28
- package/dist/dev/packages/@ember/application/instance.js +3 -22
- package/dist/dev/packages/@ember/application/namespace.js +4 -11
- package/dist/dev/packages/@ember/array/index.js +7 -15
- package/dist/dev/packages/@ember/array/proxy.js +10 -14
- package/dist/dev/packages/@ember/canary-features/index.js +1 -1
- package/dist/dev/packages/@ember/component/helper.js +1 -14
- package/dist/dev/packages/@ember/component/index.js +1355 -16
- package/dist/dev/packages/@ember/component/template-only.js +1 -9
- package/dist/dev/packages/@ember/controller/index.js +3 -19
- package/dist/dev/packages/@ember/debug/container-debug-adapter.js +0 -19
- package/dist/dev/packages/@ember/debug/data-adapter.js +4 -11
- package/dist/dev/packages/@ember/debug/index.js +2 -1
- package/dist/dev/packages/@ember/debug/lib/deprecate.js +1 -1
- package/dist/dev/packages/@ember/engine/index.js +3 -29
- package/dist/dev/packages/@ember/engine/instance.js +3 -8
- package/dist/dev/packages/@ember/helper/index.js +211 -19
- package/dist/dev/packages/@ember/instrumentation/index.js +1 -1
- package/dist/dev/packages/@ember/modifier/index.js +2 -16
- package/dist/dev/packages/@ember/modifier/on.js +1 -9
- package/dist/dev/packages/@ember/object/-internals.js +3 -11
- package/dist/dev/packages/@ember/object/compat.js +3 -10
- package/dist/dev/packages/@ember/object/computed.js +2 -12
- package/dist/dev/packages/@ember/object/core.js +10 -18
- package/dist/dev/packages/@ember/object/evented.js +2 -12
- package/dist/dev/packages/@ember/object/events.js +1 -11
- package/dist/dev/packages/@ember/object/index.js +10 -14
- package/dist/dev/packages/@ember/object/internals.js +1 -1
- package/dist/dev/packages/@ember/object/lib/computed/computed_macros.js +6 -23
- package/dist/dev/packages/@ember/object/lib/computed/reduce_computed_macros.js +3 -12
- package/dist/dev/packages/@ember/object/mixin.js +7 -10
- package/dist/dev/packages/@ember/object/observable.js +8 -12
- package/dist/dev/packages/@ember/object/observers.js +1 -11
- package/dist/dev/packages/@ember/object/promise-proxy-mixin.js +3 -13
- package/dist/dev/packages/@ember/object/proxy.js +0 -7
- package/dist/dev/packages/@ember/reactive/collections.js +589 -1
- package/dist/dev/packages/@ember/renderer/index.js +1 -14
- package/dist/dev/packages/@ember/routing/-internals.js +1 -10
- package/dist/dev/packages/@ember/routing/index.js +614 -14
- package/dist/dev/packages/@ember/routing/lib/generate_controller.js +2 -11
- package/dist/dev/packages/@ember/routing/lib/routing-service.js +7 -17
- package/dist/dev/packages/@ember/routing/lib/utils.js +2 -11
- package/dist/dev/packages/@ember/routing/route.js +12 -23
- package/dist/dev/packages/@ember/routing/router-service.js +8 -17
- package/dist/dev/packages/@ember/routing/router.js +5 -21
- package/dist/dev/packages/@ember/runloop/index.js +1 -10
- package/dist/dev/packages/@ember/service/index.js +1 -11
- package/dist/dev/packages/@ember/template/index.js +1 -14
- package/dist/dev/packages/@ember/template-compiler/lib/compile-options.js +14 -15
- package/dist/dev/packages/@ember/template-compiler/lib/dasherize-component-name.js +0 -1
- package/dist/dev/packages/@ember/template-compiler/lib/plugins/auto-import-builtins.js +13 -42
- package/dist/dev/packages/@ember/template-compiler/lib/plugins/index.js +1 -1
- package/dist/dev/packages/@ember/template-compiler/lib/plugins/transform-resolutions.js +1 -3
- package/dist/dev/packages/@ember/template-compiler/lib/template.js +2 -10
- package/dist/dev/packages/@ember/template-factory/index.js +1 -8
- package/dist/dev/packages/@ember/utils/lib/compare.js +0 -7
- package/dist/dev/packages/@ember/utils/lib/is_empty.js +1 -12
- package/dist/dev/packages/@glimmer/manager/index.js +4 -314
- package/dist/dev/packages/@glimmer/node/index.js +3 -11
- package/dist/dev/packages/@glimmer/opcode-compiler/index.js +5 -7
- package/dist/dev/packages/@glimmer/program/index.js +194 -3
- package/dist/dev/packages/@glimmer/reference/index.js +4 -5
- package/dist/dev/packages/@glimmer/runtime/index.js +17 -10
- package/dist/dev/packages/@glimmer/tracking/index.js +2 -11
- package/dist/dev/packages/@glimmer/tracking/primitives/cache/index.js +1 -11
- package/dist/dev/packages/@glimmer/util/index.js +1 -2
- package/dist/dev/packages/@glimmer/validator/index.js +4 -1253
- package/dist/dev/packages/@glimmer/vm/index.js +1 -1
- package/dist/dev/packages/@glimmer/wire-format/index.js +3 -65
- package/dist/dev/packages/ember/version.js +1 -1
- package/dist/dev/packages/ember-template-compiler/index.js +7 -7
- package/dist/dev/packages/shared-chunks/{alias-CSC0WIbj.js → alias-ZcMQckQV.js} +8 -4
- package/dist/dev/packages/shared-chunks/api-AYt3zE12.js +310 -0
- package/dist/dev/packages/shared-chunks/{api-BqXkkT0p.js → api-WvJPuo9z.js} +4 -5
- package/dist/dev/packages/shared-chunks/{args-proxy-DgXMc9b5.js → args-proxy-BNLuRFlO.js} +2 -4
- package/dist/dev/packages/shared-chunks/{array-D8PfjQHi.js → array-Bh_kUjzy.js} +2 -1
- package/dist/dev/packages/shared-chunks/cache-B7dqAS38.js +596 -0
- package/dist/dev/packages/shared-chunks/{capabilities-O_xc7Yqk.js → capabilities-CZkuOqqC.js} +0 -5
- package/dist/dev/packages/shared-chunks/chain-tags-D6tuFUj_.js +190 -0
- package/dist/dev/packages/shared-chunks/{collections-D_nY_0UJ.js → collections-DPkjqeA3.js} +0 -1
- package/dist/dev/packages/shared-chunks/{compiler-D1leQ3Gl.js → compiler-CXB_8GdR.js} +7043 -234
- package/dist/dev/packages/shared-chunks/computed-CJnghmXC.js +980 -0
- package/dist/dev/packages/shared-chunks/container-BzzHmCNj.js +404 -0
- package/dist/dev/packages/shared-chunks/curly-CvC8E_4-.js +617 -0
- package/dist/dev/packages/shared-chunks/{fragment-Cc5k9Oy4.js → curried-BVwSNqpf.js} +5 -288
- package/dist/dev/packages/shared-chunks/decorator-B5Uh5NFI.js +135 -0
- package/dist/dev/packages/shared-chunks/element-C-QcIABg.js +109 -0
- package/dist/dev/packages/shared-chunks/element-builder-kHVx0F__.js +812 -0
- package/dist/dev/packages/shared-chunks/env-g-kaAFLN.js +161 -0
- package/dist/dev/packages/shared-chunks/events-6aFVjD4k.js +180 -0
- package/dist/dev/packages/shared-chunks/get-CpJjYeJO.js +138 -0
- package/dist/dev/packages/shared-chunks/get-debug-name-CSniHBsn.js +45 -0
- package/dist/dev/packages/shared-chunks/get_properties-CIm8IAtP.js +55 -0
- package/dist/dev/packages/shared-chunks/guid-Cbq2sNV_.js +123 -0
- package/dist/dev/packages/shared-chunks/hash-D3BENmhU.js +192 -0
- package/dist/dev/packages/shared-chunks/helper-DlC4YesW.js +314 -0
- package/dist/dev/packages/shared-chunks/index-CTxkmV78.js +2500 -0
- package/dist/dev/packages/shared-chunks/index-D-xTBV4B.js +220 -0
- package/dist/dev/packages/shared-chunks/{index-BUPd6pkm.js → index-DmGmwWPJ.js} +29 -29
- package/dist/dev/packages/shared-chunks/injected_property-B4T-FzZZ.js +70 -0
- package/dist/dev/packages/shared-chunks/intern-zquhAEIg.js +51 -0
- package/dist/dev/packages/shared-chunks/internal-CbQSKXEm.js +140 -0
- package/dist/dev/packages/shared-chunks/internal-helper-Dsl9_7H_.js +7 -0
- package/dist/dev/packages/shared-chunks/{invoke-CgfoEtMT.js → invoke-B6j6DdDz.js} +3 -7
- package/dist/{prod/packages/shared-chunks/is_proxy-Cr1qlMv_.js → dev/packages/shared-chunks/is_proxy-Bzg0d4m4.js} +1 -1
- package/dist/dev/packages/shared-chunks/libraries-CHBwbR72.js +79 -0
- package/dist/dev/packages/shared-chunks/mandatory-setter-BpbAMTzV.js +107 -0
- package/dist/dev/packages/shared-chunks/meta-BmRXesrk.js +46 -0
- package/dist/{prod/packages/shared-chunks/name-C68GLLO3.js → dev/packages/shared-chunks/name-Clp4Vsod.js} +1 -1
- package/dist/dev/packages/shared-chunks/{namespace_search-uT8odThF.js → namespace_search-BfvzEQzN.js} +1 -2
- package/dist/dev/packages/shared-chunks/normalize-CKySQVU7.js +84 -0
- package/dist/dev/packages/shared-chunks/observers-C2DurkLG.js +199 -0
- package/dist/dev/packages/shared-chunks/on-D8QwT-eN.js +253 -0
- package/dist/dev/packages/shared-chunks/opcode-metadata-9iSW5JGP.js +285 -0
- package/dist/dev/packages/shared-chunks/opcodes-CplRyHl_.js +50 -0
- package/dist/dev/packages/shared-chunks/or-DBU9Ge4r.js +118 -0
- package/dist/{prod/packages/shared-chunks/program-B7SJZ5NF.js → dev/packages/shared-chunks/program-DzAfcWFj.js} +1 -1
- package/dist/dev/packages/shared-chunks/{program-context-sJz0oHOA.js → program-context-CqcQMsfa.js} +3 -3
- package/dist/dev/packages/shared-chunks/property_get-CIBS9umw.js +139 -0
- package/dist/dev/packages/shared-chunks/{property_set-DaoZXGM5.js → property_set-D3PKyisF.js} +4 -2
- package/dist/dev/packages/shared-chunks/props-fiqxqhAH.js +85 -0
- package/dist/dev/packages/shared-chunks/{reference-C3TKDRnP.js → reference-BoPB2LfI.js} +3 -4
- package/dist/dev/packages/shared-chunks/{registers-ylirb0dq.js → registers-DoamZwaG.js} +1 -1
- package/dist/{prod/packages/shared-chunks/rehydrate-builder-CUefZL4I.js → dev/packages/shared-chunks/rehydrate-builder-DdzXTaJk.js} +7 -4
- package/dist/dev/packages/shared-chunks/{render-C1HzKUcM.js → render-DDdabL30.js} +510 -15
- package/dist/{prod/packages/shared-chunks/serialize-builder-DgpXSc2Q.js → dev/packages/shared-chunks/serialize-builder-B3u9Wr3n.js} +2 -7
- package/dist/dev/packages/shared-chunks/set_properties-BghuuGJx.js +48 -0
- package/dist/dev/packages/shared-chunks/{setup-registry-B7-RknRf.js → setup-registry-XxD0xvgf.js} +34 -14
- package/dist/dev/packages/shared-chunks/spec-BXl1reqK.js +16 -0
- package/dist/dev/packages/shared-chunks/super-BBBjgF69.js +91 -0
- package/dist/dev/packages/shared-chunks/template-BRrQR6KS.js +16 -0
- package/dist/dev/packages/shared-chunks/template-only-Yluyu0DY.js +78 -0
- package/dist/dev/packages/shared-chunks/textarea-C0Us0PNJ.js +468 -0
- package/dist/dev/packages/shared-chunks/tracked-CKE4wnE6.js +148 -0
- package/dist/dev/packages/shared-chunks/tracked-data-CGnA4ytZ.js +31 -0
- package/dist/dev/packages/shared-chunks/transform-resolutions-h1ik8gqW.js +645 -0
- package/dist/dev/packages/shared-chunks/unique-id-A83bjEE-.js +32 -0
- package/dist/{prod/packages/shared-chunks/on-CLxdmpmk.js → dev/packages/shared-chunks/untouchable-this-cH6_N2LJ.js} +215 -1397
- package/dist/dev/packages/shared-chunks/well-known-_EVO9RaV.js +17 -0
- package/dist/prod/packages/@ember/-internals/container/index.js +5 -315
- package/dist/prod/packages/@ember/-internals/deprecations/index.js +1 -1
- package/dist/prod/packages/@ember/-internals/environment/index.js +3 -148
- package/dist/prod/packages/@ember/-internals/glimmer/index.js +14 -13
- package/dist/prod/packages/@ember/-internals/meta/lib/meta.js +1 -2
- package/dist/prod/packages/@ember/-internals/metal/index.js +19 -13
- package/dist/prod/packages/@ember/-internals/routing/index.js +2 -6
- package/dist/prod/packages/@ember/-internals/runtime/lib/ext/rsvp.js +1 -1
- package/dist/prod/packages/@ember/-internals/runtime/lib/mixins/-proxy.js +10 -10
- package/dist/prod/packages/@ember/-internals/runtime/lib/mixins/action_handler.js +2 -6
- package/dist/prod/packages/@ember/-internals/runtime/lib/mixins/registry_proxy.js +1 -1
- package/dist/prod/packages/@ember/-internals/runtime/lib/mixins/target_action_support.js +3 -6
- package/dist/prod/packages/@ember/-internals/string/index.js +0 -2
- package/dist/prod/packages/@ember/-internals/utils/index.js +33 -30
- package/dist/prod/packages/@ember/-internals/views/lib/compat/fallback-view-registry.js +0 -2
- package/dist/prod/packages/@ember/-internals/views/lib/mixins/action_support.js +2 -6
- package/dist/prod/packages/@ember/-internals/views/lib/system/event_dispatcher.js +3 -7
- package/dist/prod/packages/@ember/-internals/views/lib/system/utils.js +2 -2
- package/dist/prod/packages/@ember/-internals/views/lib/views/core_view.js +1 -14
- package/dist/prod/packages/@ember/-internals/views/lib/views/states.js +1 -2
- package/dist/prod/packages/@ember/application/index.js +5 -24
- package/dist/prod/packages/@ember/application/instance.js +6 -18
- package/dist/prod/packages/@ember/application/namespace.js +5 -8
- package/dist/prod/packages/@ember/array/index.js +8 -12
- package/dist/prod/packages/@ember/array/proxy.js +10 -10
- package/dist/prod/packages/@ember/canary-features/index.js +1 -1
- package/dist/prod/packages/@ember/component/helper.js +1 -12
- package/dist/prod/packages/@ember/component/index.js +1292 -15
- package/dist/prod/packages/@ember/component/template-only.js +1 -6
- package/dist/prod/packages/@ember/controller/index.js +3 -16
- package/dist/prod/packages/@ember/debug/container-debug-adapter.js +1 -15
- package/dist/prod/packages/@ember/debug/data-adapter.js +5 -7
- package/dist/prod/packages/@ember/debug/index.js +1 -0
- package/dist/prod/packages/@ember/debug/lib/deprecate.js +1 -1
- package/dist/prod/packages/@ember/engine/index.js +4 -25
- package/dist/prod/packages/@ember/engine/instance.js +4 -9
- package/dist/prod/packages/@ember/helper/index.js +211 -17
- package/dist/prod/packages/@ember/instrumentation/index.js +1 -1
- package/dist/prod/packages/@ember/modifier/index.js +2 -14
- package/dist/prod/packages/@ember/modifier/on.js +1 -6
- package/dist/prod/packages/@ember/object/-internals.js +3 -6
- package/dist/prod/packages/@ember/object/compat.js +4 -7
- package/dist/prod/packages/@ember/object/computed.js +2 -8
- package/dist/prod/packages/@ember/object/core.js +9 -15
- package/dist/prod/packages/@ember/object/evented.js +2 -7
- package/dist/prod/packages/@ember/object/events.js +1 -6
- package/dist/prod/packages/@ember/object/index.js +10 -12
- package/dist/prod/packages/@ember/object/internals.js +3 -6
- package/dist/prod/packages/@ember/object/lib/computed/computed_macros.js +6 -20
- package/dist/prod/packages/@ember/object/lib/computed/reduce_computed_macros.js +3 -9
- package/dist/prod/packages/@ember/object/mixin.js +7 -9
- package/dist/prod/packages/@ember/object/observable.js +8 -9
- package/dist/prod/packages/@ember/object/observers.js +1 -6
- package/dist/prod/packages/@ember/object/promise-proxy-mixin.js +3 -9
- package/dist/prod/packages/@ember/object/proxy.js +0 -7
- package/dist/prod/packages/@ember/reactive/collections.js +589 -1
- package/dist/prod/packages/@ember/renderer/index.js +1 -12
- package/dist/prod/packages/@ember/routing/history-location.js +1 -1
- package/dist/prod/packages/@ember/routing/index.js +581 -12
- package/dist/prod/packages/@ember/routing/lib/dsl.js +1 -1
- package/dist/prod/packages/@ember/routing/lib/generate_controller.js +2 -6
- package/dist/prod/packages/@ember/routing/lib/routing-service.js +5 -14
- package/dist/prod/packages/@ember/routing/lib/utils.js +2 -6
- package/dist/prod/packages/@ember/routing/none-location.js +1 -1
- package/dist/prod/packages/@ember/routing/route.js +12 -21
- package/dist/prod/packages/@ember/routing/router-service.js +6 -14
- package/dist/prod/packages/@ember/routing/router.js +5 -17
- package/dist/prod/packages/@ember/runloop/index.js +2 -6
- package/dist/prod/packages/@ember/service/index.js +1 -7
- package/dist/prod/packages/@ember/template/index.js +1 -12
- package/dist/prod/packages/@ember/template-compiler/lib/compile-options.js +15 -14
- package/dist/prod/packages/@ember/template-compiler/lib/dasherize-component-name.js +0 -2
- package/dist/prod/packages/@ember/template-compiler/lib/plugins/assert-against-attrs.js +1 -1
- package/dist/prod/packages/@ember/template-compiler/lib/plugins/assert-against-named-outlets.js +1 -1
- package/dist/prod/packages/@ember/template-compiler/lib/plugins/assert-input-helper-without-block.js +1 -1
- package/dist/prod/packages/@ember/template-compiler/lib/plugins/assert-reserved-named-arguments.js +1 -1
- package/dist/prod/packages/@ember/template-compiler/lib/plugins/auto-import-builtins.js +13 -42
- package/dist/prod/packages/@ember/template-compiler/lib/plugins/index.js +1 -1
- package/dist/prod/packages/@ember/template-compiler/lib/plugins/transform-each-track-array.js +1 -1
- package/dist/prod/packages/@ember/template-compiler/lib/plugins/transform-in-element.js +1 -1
- package/dist/prod/packages/@ember/template-compiler/lib/plugins/transform-resolutions.js +127 -4
- package/dist/prod/packages/@ember/template-compiler/lib/template.js +2 -7
- package/dist/prod/packages/@ember/template-factory/index.js +1 -5
- package/dist/prod/packages/@ember/utils/lib/compare.js +1 -8
- package/dist/prod/packages/@ember/utils/lib/is_empty.js +1 -7
- package/dist/prod/packages/@glimmer/manager/index.js +4 -292
- package/dist/prod/packages/@glimmer/node/index.js +3 -8
- package/dist/prod/packages/@glimmer/opcode-compiler/index.js +5 -5
- package/dist/prod/packages/@glimmer/program/index.js +194 -3
- package/dist/prod/packages/@glimmer/reference/index.js +4 -4
- package/dist/prod/packages/@glimmer/runtime/index.js +16 -8
- package/dist/prod/packages/@glimmer/tracking/index.js +2 -7
- package/dist/prod/packages/@glimmer/tracking/primitives/cache/index.js +1 -6
- package/dist/prod/packages/@glimmer/util/index.js +2 -2
- package/dist/prod/packages/@glimmer/validator/index.js +5 -1016
- package/dist/prod/packages/@glimmer/vm/index.js +1 -1
- package/dist/prod/packages/@glimmer/wire-format/index.js +3 -65
- package/dist/prod/packages/ember/version.js +1 -1
- package/dist/prod/packages/ember-template-compiler/index.js +5 -7
- package/dist/prod/packages/shared-chunks/{alias-BLBQkche.js → alias-CLuFeKoV.js} +8 -6
- package/dist/prod/packages/shared-chunks/api-CM1trl_4.js +289 -0
- package/dist/prod/packages/shared-chunks/{api-DtWa0ZaF.js → api-zh_k31vb.js} +4 -5
- package/dist/prod/packages/shared-chunks/{args-proxy-Dl0A0YWI.js → args-proxy-BDXbXCF9.js} +2 -2
- package/dist/prod/packages/shared-chunks/{array-kVQfzrQn.js → array-DHdr4__s.js} +3 -3
- package/dist/prod/packages/shared-chunks/assert-CUCJBR2C.js +19 -0
- package/dist/prod/packages/shared-chunks/cache-BIlOoPA7.js +371 -0
- package/dist/prod/packages/shared-chunks/{capabilities-DXA-L0iT.js → capabilities-_5e35539.js} +0 -3
- package/dist/prod/packages/shared-chunks/chain-tags-BJqcuCM1.js +179 -0
- package/dist/prod/packages/shared-chunks/{compiler-Bbki2GT_.js → compiler-DjQtTQGk.js} +7045 -193
- package/dist/prod/packages/shared-chunks/{namespace_search-Dcdalhj6.js → computed-2Udcmflw.js} +109 -239
- package/dist/prod/packages/shared-chunks/container-D5NwW5Fd.js +316 -0
- package/dist/prod/packages/shared-chunks/curly-BsqvV8G0.js +546 -0
- package/dist/prod/packages/shared-chunks/{fragment-D7nBU9ae.js → curried-BVwSNqpf.js} +6 -303
- package/dist/prod/packages/shared-chunks/debug-render-tree-BLtnOSbb.js +2049 -0
- package/dist/prod/packages/shared-chunks/{decorator-BdDDBUd2.js → decorator-DBCISop4.js} +1 -1
- package/dist/prod/packages/shared-chunks/element-BjFr0tO0.js +101 -0
- package/dist/prod/packages/shared-chunks/{element-builder-BmLF0C-1.js → element-builder-BPjq0rxK.js} +109 -88
- package/dist/prod/packages/shared-chunks/env-DXxsTFkM.js +158 -0
- package/dist/prod/packages/shared-chunks/events-970OxD6Q.js +175 -0
- package/dist/prod/packages/shared-chunks/get-D5wxdTkY.js +138 -0
- package/dist/prod/packages/shared-chunks/get_properties-BcAC5sGx.js +55 -0
- package/dist/prod/packages/shared-chunks/guid-Cbq2sNV_.js +123 -0
- package/dist/prod/packages/shared-chunks/hash-DcUe-meU.js +192 -0
- package/dist/prod/packages/shared-chunks/helper-Da672z4a.js +299 -0
- package/dist/prod/packages/shared-chunks/{index-CjaDF9kC.js → index--2U-v2nf.js} +18 -10
- package/dist/prod/packages/shared-chunks/index-D-xTBV4B.js +220 -0
- package/dist/prod/packages/shared-chunks/index-D87qoERP.js +2322 -0
- package/dist/prod/packages/shared-chunks/{injected_property-CTVs5FPh.js → injected_property-D9B-fPiH.js} +3 -3
- package/dist/prod/packages/shared-chunks/intern-zquhAEIg.js +51 -0
- package/dist/prod/packages/shared-chunks/internal-DidurjJB.js +137 -0
- package/dist/prod/packages/shared-chunks/internal-helper-DIbr1RgC.js +7 -0
- package/dist/prod/packages/shared-chunks/{invoke-BdJCXD-b.js → invoke-Dr_CRwA_.js} +3 -5
- package/dist/{dev/packages/shared-chunks/is_proxy-B0smdQy8.js → prod/packages/shared-chunks/is_proxy-Bzg0d4m4.js} +1 -1
- package/dist/prod/packages/shared-chunks/libraries-DaXpIDYN.js +60 -0
- package/dist/prod/packages/shared-chunks/meta-B9mldqPL.js +36 -0
- package/dist/{dev/packages/shared-chunks/name-Z7dpqvzn.js → prod/packages/shared-chunks/name-Clp4Vsod.js} +1 -1
- package/dist/prod/packages/shared-chunks/namespace_search-BfvzEQzN.js +134 -0
- package/dist/prod/packages/shared-chunks/normalize-D9jDJVGg.js +84 -0
- package/dist/prod/packages/shared-chunks/observers-Co4JALkS.js +199 -0
- package/dist/prod/packages/shared-chunks/on-C3ZQiUUD.js +228 -0
- package/dist/prod/packages/shared-chunks/opcode-metadata-9iSW5JGP.js +285 -0
- package/dist/prod/packages/shared-chunks/opcodes-CplRyHl_.js +50 -0
- package/dist/prod/packages/shared-chunks/or-oTVMuHc8.js +91 -0
- package/dist/{dev/packages/shared-chunks/program-DfV0v8aa.js → prod/packages/shared-chunks/program-B7CWdS8W.js} +1 -2
- package/dist/prod/packages/shared-chunks/{program-context-DFiwaPMR.js → program-context-CGMN-aQM.js} +3 -3
- package/dist/prod/packages/shared-chunks/property_get-hWJ0nGhW.js +122 -0
- package/dist/prod/packages/shared-chunks/{property_set-B2sZxeCw.js → property_set-Dj5-ScWk.js} +4 -5
- package/dist/prod/packages/shared-chunks/props-fiqxqhAH.js +85 -0
- package/dist/prod/packages/shared-chunks/{reference-BNqcwZWH.js → reference-BshxG6wn.js} +3 -3
- package/dist/prod/packages/shared-chunks/{registers-ylirb0dq.js → registers-DoamZwaG.js} +1 -1
- package/dist/{dev/packages/shared-chunks/rehydrate-builder-CEk2KOIk.js → prod/packages/shared-chunks/rehydrate-builder-BKg2X6Lo.js} +7 -7
- package/dist/prod/packages/shared-chunks/{render-BlriW61t.js → render-nx5-PsDW.js} +487 -12
- package/dist/{dev/packages/shared-chunks/serialize-builder-CPKxdfiH.js → prod/packages/shared-chunks/serialize-builder-BGbC30SN.js} +2 -10
- package/dist/prod/packages/shared-chunks/set_properties-oPyURk67.js +48 -0
- package/dist/prod/packages/shared-chunks/{setup-registry-DeObnZ2Z.js → setup-registry-TiaKLj5k.js} +35 -13
- package/dist/prod/packages/shared-chunks/spec-BXl1reqK.js +16 -0
- package/dist/prod/packages/shared-chunks/super-BBBjgF69.js +91 -0
- package/dist/prod/packages/shared-chunks/template-BRrQR6KS.js +16 -0
- package/dist/prod/packages/shared-chunks/template-only-BtLl0uH0.js +78 -0
- package/dist/prod/packages/shared-chunks/textarea-CPKZ1c_O.js +455 -0
- package/dist/prod/packages/shared-chunks/{tracked-Cl5l4v8b.js → tracked-CffAABMz.js} +6 -4
- package/dist/prod/packages/shared-chunks/tracked-data-C83f5V5S.js +31 -0
- package/dist/prod/packages/shared-chunks/unique-id-CfHImDRV.js +32 -0
- package/dist/prod/packages/shared-chunks/well-known-_EVO9RaV.js +17 -0
- package/docs/data.json +1368 -1031
- package/package.json +1 -1
- package/types/stable/@ember/-internals/container/lib/registry.d.ts +1 -1
- package/types/stable/@ember/-internals/deprecations/index.d.ts +1 -1
- package/types/stable/@ember/-internals/environment/lib/env.d.ts +11 -0
- package/types/stable/@ember/-internals/glimmer/index.d.ts +1 -1
- package/types/stable/@ember/-internals/glimmer/lib/component-managers/curly.d.ts +1 -1
- package/types/stable/@ember/-internals/glimmer/lib/component-managers/mount.d.ts +1 -1
- package/types/stable/@ember/-internals/glimmer/lib/component-managers/outlet.d.ts +1 -1
- package/types/stable/@ember/-internals/glimmer/lib/component-managers/route-template.d.ts +2 -2
- package/types/stable/@ember/-internals/glimmer/lib/component.d.ts +9 -7
- package/types/stable/@ember/-internals/glimmer/lib/components/abstract-input.d.ts +1 -1
- package/types/stable/@ember/-internals/glimmer/lib/dom.d.ts +6 -2
- package/types/stable/@ember/-internals/glimmer/lib/environment.d.ts +1 -1
- package/types/stable/@ember/-internals/glimmer/lib/helper.d.ts +1 -1
- package/types/stable/@ember/-internals/glimmer/lib/renderer.d.ts +3 -3
- package/types/stable/@ember/-internals/glimmer/lib/setup-registry.d.ts +1 -1
- package/types/stable/@ember/-internals/glimmer/lib/utils/bindings.d.ts +1 -1
- package/types/stable/@ember/-internals/glimmer/lib/utils/curly-component-state-bucket.d.ts +3 -2
- package/types/stable/@ember/-internals/glimmer/lib/utils/iterator.d.ts +1 -1
- package/types/stable/@ember/-internals/glimmer/lib/utils/managers.d.ts +2 -1
- package/types/stable/@ember/-internals/glimmer/lib/utils/serialization-first-node-helpers.d.ts +1 -1
- package/types/stable/@ember/-internals/glimmer/lib/utils/string.d.ts +1 -1
- package/types/stable/@ember/-internals/meta/lib/meta.d.ts +3 -2
- package/types/stable/@ember/-internals/metal/lib/cache.d.ts +1 -1
- package/types/stable/@ember/-internals/metal/lib/chain-tags.d.ts +3 -2
- package/types/stable/@ember/-internals/metal/lib/computed.d.ts +1 -1
- package/types/stable/@ember/-internals/metal/lib/decorator.d.ts +1 -1
- package/types/stable/@ember/-internals/metal/lib/deprecate_property.d.ts +1 -1
- package/types/stable/@ember/-internals/metal/lib/events.d.ts +1 -1
- package/types/stable/@ember/-internals/metal/lib/observer.d.ts +1 -1
- package/types/stable/@ember/-internals/metal/lib/properties.d.ts +1 -1
- package/types/stable/@ember/-internals/metal/lib/property_events.d.ts +1 -1
- package/types/stable/@ember/-internals/metal/lib/tags.d.ts +2 -1
- package/types/stable/@ember/-internals/runtime/lib/mixins/container_proxy.d.ts +1 -1
- package/types/stable/@ember/-internals/runtime/lib/mixins/registry_proxy.d.ts +1 -1
- package/types/stable/@ember/-internals/utils/lib/is_proxy.d.ts +1 -1
- package/types/stable/@ember/-internals/utils/lib/mandatory-setter.d.ts +1 -1
- package/types/stable/@ember/-internals/views/lib/system/utils.d.ts +1 -1
- package/types/stable/@ember/-internals/views/lib/views/core_view.d.ts +2 -2
- package/types/stable/@ember/-internals/views/lib/views/states.d.ts +1 -1
- package/types/stable/@ember/application/index.d.ts +5 -4
- package/types/stable/@ember/application/instance.d.ts +4 -3
- package/types/stable/@ember/application/namespace.d.ts +1 -1
- package/types/stable/@ember/array/proxy.d.ts +4 -3
- package/types/stable/@ember/component/helper.d.ts +1 -1
- package/types/stable/@ember/component/index.d.ts +6 -3
- package/types/stable/@ember/controller/index.d.ts +2 -2
- package/types/stable/@ember/debug/container-debug-adapter.d.ts +1 -1
- package/types/stable/@ember/engine/index.d.ts +3 -3
- package/types/stable/@ember/engine/instance.d.ts +4 -3
- package/types/stable/@ember/helper/index.d.ts +223 -3
- package/types/stable/@ember/modifier/index.d.ts +1 -1
- package/types/stable/@ember/object/-internals.d.ts +2 -2
- package/types/stable/@ember/object/compat.d.ts +2 -2
- package/types/stable/@ember/object/computed.d.ts +3 -1
- package/types/stable/@ember/object/evented.d.ts +1 -1
- package/types/stable/@ember/object/events.d.ts +1 -1
- package/types/stable/@ember/object/index.d.ts +8 -2
- package/types/stable/@ember/object/lib/computed/computed_macros.d.ts +1 -1
- package/types/stable/@ember/object/mixin.d.ts +1 -1
- package/types/stable/@ember/object/observers.d.ts +1 -1
- package/types/stable/@ember/object/proxy.d.ts +1 -1
- package/types/stable/@ember/reactive/collections.d.ts +6 -6
- package/types/stable/@ember/renderer/index.d.ts +2 -2
- package/types/stable/@ember/routing/index.d.ts +1 -1
- package/types/stable/@ember/routing/lib/controller_for.d.ts +2 -2
- package/types/stable/@ember/routing/route.d.ts +2 -2
- package/types/stable/@ember/routing/router.d.ts +2 -2
- package/types/stable/@ember/service/index.d.ts +1 -1
- package/types/stable/@ember/template/index.d.ts +1 -1
- package/types/stable/@ember/template-compiler/lib/dasherize-component-name.d.ts +1 -1
- package/types/stable/@ember/template-compiler/lib/plugins/assert-against-attrs.d.ts +1 -1
- package/types/stable/@ember/template-compiler/lib/plugins/assert-against-named-outlets.d.ts +1 -1
- package/types/stable/@ember/template-compiler/lib/plugins/assert-input-helper-without-block.d.ts +1 -1
- package/types/stable/@ember/template-compiler/lib/plugins/assert-reserved-named-arguments.d.ts +1 -1
- package/types/stable/@ember/template-compiler/lib/plugins/auto-import-builtins.d.ts +1 -4
- package/types/stable/@ember/template-compiler/lib/plugins/transform-action-syntax.d.ts +1 -1
- package/types/stable/@ember/template-compiler/lib/plugins/transform-each-in-into-each.d.ts +1 -1
- package/types/stable/@ember/template-compiler/lib/plugins/transform-each-track-array.d.ts +1 -1
- package/types/stable/@ember/template-compiler/lib/plugins/transform-in-element.d.ts +1 -1
- package/types/stable/@ember/template-compiler/lib/plugins/transform-quoted-bindings-into-just-bindings.d.ts +1 -1
- package/types/stable/@ember/template-compiler/lib/plugins/transform-resolutions.d.ts +1 -1
- package/types/stable/@ember/template-compiler/lib/plugins/transform-wrap-mount-and-outlet.d.ts +1 -1
- package/types/stable/@ember/template-compiler/lib/plugins/utils.d.ts +1 -1
- package/types/stable/@ember/template-compiler/lib/system/calculate-location-display.d.ts +1 -1
- package/types/stable/@ember/template-compiler/lib/types.d.ts +2 -1
- package/types/stable/@ember/template-factory/index.d.ts +1 -1
- package/types/stable/@glimmer/compiler/lib/builder/builder-interface.d.ts +2 -2
- package/types/stable/@glimmer/compiler/lib/builder/builder.d.ts +2 -2
- package/types/stable/@glimmer/compiler/lib/compiler.d.ts +1 -1
- package/types/stable/@glimmer/compiler/lib/passes/1-normalization/context.d.ts +2 -1
- package/types/stable/@glimmer/compiler/lib/passes/1-normalization/index.d.ts +2 -1
- package/types/stable/@glimmer/compiler/lib/passes/1-normalization/keywords/impl.d.ts +2 -1
- package/types/stable/@glimmer/compiler/lib/passes/1-normalization/keywords/utils/curry.d.ts +1 -1
- package/types/stable/@glimmer/compiler/lib/passes/1-normalization/keywords/utils/dynamic-vars.d.ts +1 -1
- package/types/stable/@glimmer/compiler/lib/passes/1-normalization/keywords/utils/has-block.d.ts +2 -1
- package/types/stable/@glimmer/compiler/lib/passes/1-normalization/keywords/utils/if-unless.d.ts +1 -1
- package/types/stable/@glimmer/compiler/lib/passes/1-normalization/keywords/utils/log.d.ts +1 -1
- package/types/stable/@glimmer/compiler/lib/passes/1-normalization/visitors/element/classified.d.ts +1 -1
- package/types/stable/@glimmer/compiler/lib/passes/1-normalization/visitors/element/component.d.ts +1 -1
- package/types/stable/@glimmer/compiler/lib/passes/1-normalization/visitors/element/simple-element.d.ts +2 -1
- package/types/stable/@glimmer/compiler/lib/passes/1-normalization/visitors/expressions.d.ts +1 -1
- package/types/stable/@glimmer/compiler/lib/passes/1-normalization/visitors/statements.d.ts +1 -1
- package/types/stable/@glimmer/compiler/lib/passes/1-normalization/visitors/strict-mode.d.ts +1 -1
- package/types/stable/@glimmer/compiler/lib/passes/2-encoding/expressions.d.ts +1 -1
- package/types/stable/@glimmer/compiler/lib/passes/2-encoding/mir.d.ts +3 -1
- package/types/stable/@glimmer/compiler/lib/shared/result.d.ts +1 -1
- package/types/stable/@glimmer/manager/lib/public/component.d.ts +1 -1
- package/types/stable/@glimmer/manager/lib/util/args-proxy.d.ts +1 -1
- package/types/stable/@glimmer/manager/lib/util/capabilities.d.ts +1 -1
- package/types/stable/@glimmer/node/lib/node-dom-helper.d.ts +1 -1
- package/types/stable/@glimmer/opcode-compiler/lib/opcode-builder/helpers/components.d.ts +1 -1
- package/types/stable/@glimmer/runtime/index.d.ts +9 -4
- package/types/stable/@glimmer/runtime/lib/compiled/expressions/concat.d.ts +1 -1
- package/types/stable/@glimmer/runtime/lib/compiled/opcodes/-debug-strip.d.ts +4 -3
- package/types/stable/@glimmer/runtime/lib/compiled/opcodes/component.d.ts +1 -1
- package/types/stable/@glimmer/runtime/lib/compiled/opcodes/dom.d.ts +2 -2
- package/types/stable/@glimmer/runtime/lib/compiled/opcodes/vm.d.ts +2 -2
- package/types/stable/@glimmer/runtime/lib/component/template-only.d.ts +1 -1
- package/types/stable/@glimmer/runtime/lib/curried-value.d.ts +1 -1
- package/types/stable/@glimmer/runtime/lib/helpers/and.d.ts +3 -0
- package/types/stable/@glimmer/runtime/lib/helpers/eq.d.ts +8 -0
- package/types/stable/@glimmer/runtime/lib/helpers/gt.d.ts +8 -0
- package/types/stable/@glimmer/runtime/lib/helpers/gte.d.ts +8 -0
- package/types/stable/@glimmer/runtime/lib/helpers/invoke.d.ts +1 -1
- package/types/stable/@glimmer/runtime/lib/helpers/lt.d.ts +8 -0
- package/types/stable/@glimmer/runtime/lib/helpers/lte.d.ts +8 -0
- package/types/stable/@glimmer/runtime/lib/helpers/neq.d.ts +8 -0
- package/types/stable/@glimmer/runtime/lib/helpers/not.d.ts +3 -0
- package/types/stable/@glimmer/runtime/lib/helpers/or.d.ts +3 -0
- package/types/stable/@glimmer/runtime/lib/opcodes.d.ts +2 -2
- package/types/stable/@glimmer/runtime/lib/references/class-list.d.ts +1 -1
- package/types/stable/@glimmer/runtime/lib/references/curry-value.d.ts +1 -1
- package/types/stable/@glimmer/runtime/lib/render.d.ts +1 -1
- package/types/stable/@glimmer/runtime/lib/scope.d.ts +1 -1
- package/types/stable/@glimmer/runtime/lib/vm/append.d.ts +3 -2
- package/types/stable/@glimmer/runtime/lib/vm/arguments.d.ts +2 -2
- package/types/stable/@glimmer/runtime/lib/vm/content/text.d.ts +1 -1
- package/types/stable/@glimmer/runtime/lib/vm/element-builder.d.ts +1 -1
- package/types/stable/@glimmer/runtime/lib/vm/low-level.d.ts +2 -1
- package/types/stable/@glimmer/runtime/lib/vm/rehydrate-builder.d.ts +1 -1
- package/types/stable/@glimmer/runtime/lib/vm/update.d.ts +2 -1
- package/types/stable/@glimmer/syntax/lib/keywords.d.ts +2 -2
- package/types/stable/@glimmer/tracking/index.d.ts +2 -1
- package/types/stable/@glimmer/tracking/primitives/cache.d.ts +1 -1
- package/types/stable/index.d.ts +9 -0
- package/dist/dev/packages/shared-chunks/constants-p7AL-pog.js +0 -213
- package/dist/dev/packages/shared-chunks/dynamic-BfDKO5NI.js +0 -3823
- package/dist/dev/packages/shared-chunks/element-builder-DO43ztVP.js +0 -404
- package/dist/dev/packages/shared-chunks/index-QZstta6s.js +0 -6306
- package/dist/dev/packages/shared-chunks/mandatory-setter-DHZe7-kW.js +0 -425
- package/dist/dev/packages/shared-chunks/observers-Bj9qLVau.js +0 -2062
- package/dist/dev/packages/shared-chunks/set_properties-kVGzZL_a.js +0 -100
- package/dist/dev/packages/shared-chunks/transform-resolutions-D-YtZ0_g.js +0 -7458
- package/dist/prod/packages/shared-chunks/constants-2M371WiB.js +0 -210
- package/dist/prod/packages/shared-chunks/index-6pnzcm45.js +0 -5931
- package/dist/prod/packages/shared-chunks/observers-tZ2aOzr4.js +0 -714
- package/dist/prod/packages/shared-chunks/set_properties-C1T46IiN.js +0 -101
- package/dist/prod/packages/shared-chunks/super-Cm_a_cLQ.js +0 -275
- package/dist/prod/packages/shared-chunks/transform-resolutions-DR4GLmR2.js +0 -6936
- package/dist/prod/packages/shared-chunks/{collections-GpG8lT2g.js → collections-C3Y8z_9v.js} +9 -9
|
@@ -1,2062 +0,0 @@
|
|
|
1
|
-
import { peekMeta, meta } from '../@ember/-internals/meta/lib/meta.js';
|
|
2
|
-
import { a as setupMandatorySetter, i as isObject, h as setListeners, b as setWithMandatorySetter } from './mandatory-setter-DHZe7-kW.js';
|
|
3
|
-
import { warn, debug } from '../@ember/debug/index.js';
|
|
4
|
-
import { isDestroyed, registerDestructor } from '../@glimmer/destroyable/index.js';
|
|
5
|
-
import { tagFor, dirtyTagFor, CONSTANT_TAG, combine, validateTag, tagMetaFor, createUpdatableTag, updateTag as UPDATE_TAG, valueForTag, CURRENT_TAG, untrack, ALLOW_CYCLES, consumeTag, track, isTracking, trackedData } from '../@glimmer/validator/index.js';
|
|
6
|
-
import './debug-to-string-CFb7h0lY.js';
|
|
7
|
-
import '../@glimmer/global-context/index.js';
|
|
8
|
-
import './reference-C3TKDRnP.js';
|
|
9
|
-
import './capabilities-O_xc7Yqk.js';
|
|
10
|
-
import { ENV } from '../@ember/-internals/environment/index.js';
|
|
11
|
-
import { assert } from '../@ember/debug/lib/assert.js';
|
|
12
|
-
import { t as toString } from './to-string-C7M8LBLH.js';
|
|
13
|
-
import { g as getCustomTagFor } from './args-proxy-DgXMc9b5.js';
|
|
14
|
-
import { s as setProxy } from './is_proxy-B0smdQy8.js';
|
|
15
|
-
import { isEmberArray } from '../@ember/array/-internals.js';
|
|
16
|
-
import { C as Cache } from './cache-qDyqAcpg.js';
|
|
17
|
-
import VERSION from '../ember/version.js';
|
|
18
|
-
import { getOwner } from '../@ember/-internals/owner/index.js';
|
|
19
|
-
import inspect from '../@ember/debug/lib/inspect.js';
|
|
20
|
-
|
|
21
|
-
function objectAt(array, index) {
|
|
22
|
-
if (Array.isArray(array)) {
|
|
23
|
-
return array[index];
|
|
24
|
-
} else {
|
|
25
|
-
return array.objectAt(index);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/////////
|
|
30
|
-
|
|
31
|
-
// This is exported for `@tracked`, but should otherwise be avoided. Use `tagForObject`.
|
|
32
|
-
const SELF_TAG = Symbol('SELF_TAG');
|
|
33
|
-
function tagForProperty(obj, propertyKey, addMandatorySetter = false, meta) {
|
|
34
|
-
let customTagFor = getCustomTagFor(obj);
|
|
35
|
-
if (customTagFor !== undefined) {
|
|
36
|
-
return customTagFor(obj, propertyKey, addMandatorySetter);
|
|
37
|
-
}
|
|
38
|
-
let tag = tagFor(obj, propertyKey, meta);
|
|
39
|
-
if (addMandatorySetter) {
|
|
40
|
-
setupMandatorySetter(tag, obj, propertyKey);
|
|
41
|
-
}
|
|
42
|
-
return tag;
|
|
43
|
-
}
|
|
44
|
-
function tagForObject(obj) {
|
|
45
|
-
if (isObject(obj)) {
|
|
46
|
-
{
|
|
47
|
-
(!(!isDestroyed(obj)) && assert(isDestroyed(obj) ? `Cannot create a new tag for \`${toString(obj)}\` after it has been destroyed.` : '', !isDestroyed(obj)));
|
|
48
|
-
}
|
|
49
|
-
return tagFor(obj, SELF_TAG);
|
|
50
|
-
}
|
|
51
|
-
return CONSTANT_TAG;
|
|
52
|
-
}
|
|
53
|
-
function markObjectAsDirty(obj, propertyKey) {
|
|
54
|
-
dirtyTagFor(obj, propertyKey);
|
|
55
|
-
dirtyTagFor(obj, SELF_TAG);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const CHAIN_PASS_THROUGH = new WeakSet();
|
|
59
|
-
function finishLazyChains(meta, key, value) {
|
|
60
|
-
let lazyTags = meta.readableLazyChainsFor(key);
|
|
61
|
-
if (lazyTags === undefined) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (isObject(value)) {
|
|
65
|
-
for (let [tag, deps] of lazyTags) {
|
|
66
|
-
UPDATE_TAG(tag, getChainTagsForKey(value, deps, tagMetaFor(value), peekMeta(value)));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
lazyTags.length = 0;
|
|
70
|
-
}
|
|
71
|
-
function getChainTagsForKeys(obj, keys, tagMeta, meta) {
|
|
72
|
-
let tags = [];
|
|
73
|
-
for (let key of keys) {
|
|
74
|
-
getChainTags(tags, obj, key, tagMeta, meta);
|
|
75
|
-
}
|
|
76
|
-
return combine(tags);
|
|
77
|
-
}
|
|
78
|
-
function getChainTagsForKey(obj, key, tagMeta, meta) {
|
|
79
|
-
return combine(getChainTags([], obj, key, tagMeta, meta));
|
|
80
|
-
}
|
|
81
|
-
function getChainTags(chainTags, obj, path, tagMeta, meta$1) {
|
|
82
|
-
let current = obj;
|
|
83
|
-
let currentTagMeta = tagMeta;
|
|
84
|
-
let currentMeta = meta$1;
|
|
85
|
-
let pathLength = path.length;
|
|
86
|
-
let segmentEnd = -1;
|
|
87
|
-
// prevent closures
|
|
88
|
-
let segment, descriptor;
|
|
89
|
-
while (true) {
|
|
90
|
-
let lastSegmentEnd = segmentEnd + 1;
|
|
91
|
-
segmentEnd = path.indexOf('.', lastSegmentEnd);
|
|
92
|
-
if (segmentEnd === -1) {
|
|
93
|
-
segmentEnd = pathLength;
|
|
94
|
-
}
|
|
95
|
-
segment = path.slice(lastSegmentEnd, segmentEnd);
|
|
96
|
-
|
|
97
|
-
// If the segment is an @each, we can process it and then break
|
|
98
|
-
if (segment === '@each' && segmentEnd !== pathLength) {
|
|
99
|
-
lastSegmentEnd = segmentEnd + 1;
|
|
100
|
-
segmentEnd = path.indexOf('.', lastSegmentEnd);
|
|
101
|
-
let arrLength = current.length;
|
|
102
|
-
if (typeof arrLength !== 'number' ||
|
|
103
|
-
// TODO: should the second test be `isEmberArray` instead?
|
|
104
|
-
!(Array.isArray(current) || 'objectAt' in current)) {
|
|
105
|
-
// If the current object isn't an array, there's nothing else to do,
|
|
106
|
-
// we don't watch individual properties. Break out of the loop.
|
|
107
|
-
break;
|
|
108
|
-
} else if (arrLength === 0) {
|
|
109
|
-
// Fast path for empty arrays
|
|
110
|
-
chainTags.push(tagForProperty(current, '[]'));
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
if (segmentEnd === -1) {
|
|
114
|
-
segment = path.slice(lastSegmentEnd);
|
|
115
|
-
} else {
|
|
116
|
-
// Deprecated, remove once we turn the deprecation into an assertion
|
|
117
|
-
segment = path.slice(lastSegmentEnd, segmentEnd);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Push the tags for each item's property
|
|
121
|
-
for (let i = 0; i < arrLength; i++) {
|
|
122
|
-
let item = objectAt(current, i);
|
|
123
|
-
if (item) {
|
|
124
|
-
(!(typeof item === 'object') && assert(`When using @each to observe the array \`${current.toString()}\`, the items in the array must be objects`, typeof item === 'object'));
|
|
125
|
-
chainTags.push(tagForProperty(item, segment, true));
|
|
126
|
-
currentMeta = peekMeta(item);
|
|
127
|
-
descriptor = currentMeta !== null ? currentMeta.peekDescriptors(segment) : undefined;
|
|
128
|
-
|
|
129
|
-
// If the key is an alias, we need to bootstrap it
|
|
130
|
-
if (descriptor !== undefined && typeof descriptor.altKey === 'string') {
|
|
131
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
132
|
-
item[segment];
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Push the tag for the array length itself
|
|
138
|
-
chainTags.push(tagForProperty(current, '[]', true, currentTagMeta));
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
let propertyTag = tagForProperty(current, segment, true, currentTagMeta);
|
|
142
|
-
descriptor = currentMeta !== null ? currentMeta.peekDescriptors(segment) : undefined;
|
|
143
|
-
chainTags.push(propertyTag);
|
|
144
|
-
|
|
145
|
-
// If we're at the end of the path, processing the last segment, and it's
|
|
146
|
-
// not an alias, we should _not_ get the last value, since we already have
|
|
147
|
-
// its tag. There's no reason to access it and do more work.
|
|
148
|
-
if (segmentEnd === pathLength) {
|
|
149
|
-
// If the key was an alias, we should always get the next value in order to
|
|
150
|
-
// bootstrap the alias. This is because aliases, unlike other CPs, should
|
|
151
|
-
// always be in sync with the aliased value.
|
|
152
|
-
if (CHAIN_PASS_THROUGH.has(descriptor)) {
|
|
153
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
154
|
-
current[segment];
|
|
155
|
-
}
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
if (descriptor === undefined) {
|
|
159
|
-
// If the descriptor is undefined, then its a normal property, so we should
|
|
160
|
-
// lookup the value to chain off of like normal.
|
|
161
|
-
|
|
162
|
-
if (!(segment in current) && typeof current.unknownProperty === 'function') {
|
|
163
|
-
current = current.unknownProperty(segment);
|
|
164
|
-
} else {
|
|
165
|
-
current = current[segment];
|
|
166
|
-
}
|
|
167
|
-
} else if (CHAIN_PASS_THROUGH.has(descriptor)) {
|
|
168
|
-
current = current[segment];
|
|
169
|
-
} else {
|
|
170
|
-
// If the descriptor is defined, then its a normal CP (not an alias, which
|
|
171
|
-
// would have been handled earlier). We get the last revision to check if
|
|
172
|
-
// the CP is still valid, and if so we use the cached value. If not, then
|
|
173
|
-
// we create a lazy chain lookup, and the next time the CP is calculated,
|
|
174
|
-
// it will update that lazy chain.
|
|
175
|
-
let instanceMeta = currentMeta.source === current ? currentMeta : meta(current);
|
|
176
|
-
let lastRevision = instanceMeta.revisionFor(segment);
|
|
177
|
-
if (lastRevision !== undefined && validateTag(propertyTag, lastRevision)) {
|
|
178
|
-
current = instanceMeta.valueFor(segment);
|
|
179
|
-
} else {
|
|
180
|
-
// use metaFor here to ensure we have the meta for the instance
|
|
181
|
-
let lazyChains = instanceMeta.writableLazyChainsFor(segment);
|
|
182
|
-
let rest = path.substring(segmentEnd + 1);
|
|
183
|
-
let placeholderTag = createUpdatableTag();
|
|
184
|
-
lazyChains.push([placeholderTag, rest]);
|
|
185
|
-
chainTags.push(placeholderTag);
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
if (!isObject(current)) {
|
|
190
|
-
// we've hit the end of the chain for now, break out
|
|
191
|
-
break;
|
|
192
|
-
}
|
|
193
|
-
currentTagMeta = tagMetaFor(current);
|
|
194
|
-
currentMeta = peekMeta(current);
|
|
195
|
-
}
|
|
196
|
-
return chainTags;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Same as built-in MethodDecorator but with more arguments
|
|
200
|
-
|
|
201
|
-
function isElementDescriptor(args) {
|
|
202
|
-
let [maybeTarget, maybeKey, maybeDesc] = args;
|
|
203
|
-
return (
|
|
204
|
-
// Ensure we have the right number of args
|
|
205
|
-
args.length === 3 && (
|
|
206
|
-
// Make sure the target is a class or object (prototype)
|
|
207
|
-
typeof maybeTarget === 'function' || typeof maybeTarget === 'object' && maybeTarget !== null) &&
|
|
208
|
-
// Make sure the key is a string
|
|
209
|
-
typeof maybeKey === 'string' && (
|
|
210
|
-
// Make sure the descriptor is the right shape
|
|
211
|
-
typeof maybeDesc === 'object' && maybeDesc !== null || maybeDesc === undefined)
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
function nativeDescDecorator(propertyDesc) {
|
|
215
|
-
let decorator = function () {
|
|
216
|
-
return propertyDesc;
|
|
217
|
-
};
|
|
218
|
-
setClassicDecorator(decorator);
|
|
219
|
-
return decorator;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
Objects of this type can implement an interface to respond to requests to
|
|
224
|
-
get and set. The default implementation handles simple properties.
|
|
225
|
-
|
|
226
|
-
@class Descriptor
|
|
227
|
-
@private
|
|
228
|
-
*/
|
|
229
|
-
class ComputedDescriptor {
|
|
230
|
-
enumerable = true;
|
|
231
|
-
configurable = true;
|
|
232
|
-
_dependentKeys = undefined;
|
|
233
|
-
_meta = undefined;
|
|
234
|
-
setup(_obj, keyName, _propertyDesc, meta) {
|
|
235
|
-
meta.writeDescriptors(keyName, this);
|
|
236
|
-
}
|
|
237
|
-
teardown(_obj, keyName, meta) {
|
|
238
|
-
meta.removeDescriptors(keyName);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
let COMPUTED_GETTERS;
|
|
242
|
-
{
|
|
243
|
-
COMPUTED_GETTERS = new WeakSet();
|
|
244
|
-
}
|
|
245
|
-
function DESCRIPTOR_GETTER_FUNCTION(name, descriptor) {
|
|
246
|
-
function getter() {
|
|
247
|
-
return descriptor.get(this, name);
|
|
248
|
-
}
|
|
249
|
-
{
|
|
250
|
-
COMPUTED_GETTERS.add(getter);
|
|
251
|
-
}
|
|
252
|
-
return getter;
|
|
253
|
-
}
|
|
254
|
-
function DESCRIPTOR_SETTER_FUNCTION(name, descriptor) {
|
|
255
|
-
let set = function CPSETTER_FUNCTION(value) {
|
|
256
|
-
return descriptor.set(this, name, value);
|
|
257
|
-
};
|
|
258
|
-
COMPUTED_SETTERS.add(set);
|
|
259
|
-
return set;
|
|
260
|
-
}
|
|
261
|
-
const COMPUTED_SETTERS = new WeakSet();
|
|
262
|
-
function makeComputedDecorator(desc, DecoratorClass) {
|
|
263
|
-
let decorator = function COMPUTED_DECORATOR(target, key, propertyDesc, maybeMeta, isClassicDecorator) {
|
|
264
|
-
(!(isClassicDecorator || !propertyDesc || !propertyDesc.get || !COMPUTED_GETTERS.has(propertyDesc.get)) && assert(`Only one computed property decorator can be applied to a class field or accessor, but '${key}' was decorated twice. You may have added the decorator to both a getter and setter, which is unnecessary.`, isClassicDecorator || !propertyDesc || !propertyDesc.get || !COMPUTED_GETTERS.has(propertyDesc.get)));
|
|
265
|
-
let meta$1 = arguments.length === 3 ? meta(target) : maybeMeta;
|
|
266
|
-
desc.setup(target, key, propertyDesc, meta$1);
|
|
267
|
-
let computedDesc = {
|
|
268
|
-
enumerable: desc.enumerable,
|
|
269
|
-
configurable: desc.configurable,
|
|
270
|
-
get: DESCRIPTOR_GETTER_FUNCTION(key, desc),
|
|
271
|
-
set: DESCRIPTOR_SETTER_FUNCTION(key, desc)
|
|
272
|
-
};
|
|
273
|
-
return computedDesc;
|
|
274
|
-
};
|
|
275
|
-
setClassicDecorator(decorator, desc);
|
|
276
|
-
Object.setPrototypeOf(decorator, DecoratorClass.prototype);
|
|
277
|
-
return decorator;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/////////////
|
|
281
|
-
|
|
282
|
-
const DECORATOR_DESCRIPTOR_MAP = new WeakMap();
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
Returns the CP descriptor associated with `obj` and `keyName`, if any.
|
|
286
|
-
|
|
287
|
-
@method descriptorForProperty
|
|
288
|
-
@param {Object} obj the object to check
|
|
289
|
-
@param {String} keyName the key to check
|
|
290
|
-
@return {Descriptor}
|
|
291
|
-
@private
|
|
292
|
-
*/
|
|
293
|
-
function descriptorForProperty(obj, keyName, _meta) {
|
|
294
|
-
(!(obj !== null) && assert('Cannot call `descriptorForProperty` on null', obj !== null));
|
|
295
|
-
(!(obj !== undefined) && assert('Cannot call `descriptorForProperty` on undefined', obj !== undefined));
|
|
296
|
-
(!(typeof obj === 'object' || typeof obj === 'function') && assert(`Cannot call \`descriptorForProperty\` on ${typeof obj}`, typeof obj === 'object' || typeof obj === 'function'));
|
|
297
|
-
let meta = _meta === undefined ? peekMeta(obj) : _meta;
|
|
298
|
-
if (meta !== null) {
|
|
299
|
-
return meta.peekDescriptors(keyName);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
function descriptorForDecorator(dec) {
|
|
303
|
-
return DECORATOR_DESCRIPTOR_MAP.get(dec);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
Check whether a value is a decorator
|
|
308
|
-
|
|
309
|
-
@method isClassicDecorator
|
|
310
|
-
@param {any} possibleDesc the value to check
|
|
311
|
-
@return {boolean}
|
|
312
|
-
@private
|
|
313
|
-
*/
|
|
314
|
-
function isClassicDecorator(dec) {
|
|
315
|
-
return typeof dec === 'function' && DECORATOR_DESCRIPTOR_MAP.has(dec);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
Set a value as a decorator
|
|
320
|
-
|
|
321
|
-
@method setClassicDecorator
|
|
322
|
-
@param {function} decorator the value to mark as a decorator
|
|
323
|
-
@private
|
|
324
|
-
*/
|
|
325
|
-
function setClassicDecorator(dec, value = true) {
|
|
326
|
-
DECORATOR_DESCRIPTOR_MAP.set(dec, value);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
@module @ember/object
|
|
331
|
-
*/
|
|
332
|
-
|
|
333
|
-
const END_WITH_EACH_REGEX = /\.@each$/;
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
Expands `pattern`, invoking `callback` for each expansion.
|
|
337
|
-
|
|
338
|
-
The only pattern supported is brace-expansion, anything else will be passed
|
|
339
|
-
once to `callback` directly.
|
|
340
|
-
|
|
341
|
-
Example
|
|
342
|
-
|
|
343
|
-
```js
|
|
344
|
-
import { expandProperties } from '@ember/object/computed';
|
|
345
|
-
|
|
346
|
-
function echo(arg){ console.log(arg); }
|
|
347
|
-
|
|
348
|
-
expandProperties('foo.bar', echo); //=> 'foo.bar'
|
|
349
|
-
expandProperties('{foo,bar}', echo); //=> 'foo', 'bar'
|
|
350
|
-
expandProperties('foo.{bar,baz}', echo); //=> 'foo.bar', 'foo.baz'
|
|
351
|
-
expandProperties('{foo,bar}.baz', echo); //=> 'foo.baz', 'bar.baz'
|
|
352
|
-
expandProperties('foo.{bar,baz}.[]', echo) //=> 'foo.bar.[]', 'foo.baz.[]'
|
|
353
|
-
expandProperties('{foo,bar}.{spam,eggs}', echo) //=> 'foo.spam', 'foo.eggs', 'bar.spam', 'bar.eggs'
|
|
354
|
-
expandProperties('{foo}.bar.{baz}') //=> 'foo.bar.baz'
|
|
355
|
-
```
|
|
356
|
-
|
|
357
|
-
@method expandProperties
|
|
358
|
-
@static
|
|
359
|
-
@for @ember/object/computed
|
|
360
|
-
@public
|
|
361
|
-
@param {String} pattern The property pattern to expand.
|
|
362
|
-
@param {Function} callback The callback to invoke. It is invoked once per
|
|
363
|
-
expansion, and is passed the expansion.
|
|
364
|
-
*/
|
|
365
|
-
function expandProperties(pattern, callback) {
|
|
366
|
-
(!(typeof pattern === 'string') && assert(`A computed property key must be a string, you passed ${typeof pattern} ${pattern}`, typeof pattern === 'string'));
|
|
367
|
-
(!(pattern.indexOf(' ') === -1) && assert('Brace expanded properties cannot contain spaces, e.g. "user.{firstName, lastName}" should be "user.{firstName,lastName}"', pattern.indexOf(' ') === -1)); // regex to look for double open, double close, or unclosed braces
|
|
368
|
-
(!(pattern.match(/\{[^}{]*\{|\}[^}{]*\}|\{[^}]*$/g) === null) && assert(`Brace expanded properties have to be balanced and cannot be nested, pattern: ${pattern}`, pattern.match(/\{[^}{]*\{|\}[^}{]*\}|\{[^}]*$/g) === null));
|
|
369
|
-
let start = pattern.indexOf('{');
|
|
370
|
-
if (start < 0) {
|
|
371
|
-
callback(pattern.replace(END_WITH_EACH_REGEX, '.[]'));
|
|
372
|
-
} else {
|
|
373
|
-
dive('', pattern, start, callback);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
function dive(prefix, pattern, start, callback) {
|
|
377
|
-
let end = pattern.indexOf('}'),
|
|
378
|
-
i = 0,
|
|
379
|
-
newStart,
|
|
380
|
-
arrayLength;
|
|
381
|
-
let tempArr = pattern.substring(start + 1, end).split(',');
|
|
382
|
-
let after = pattern.substring(end + 1);
|
|
383
|
-
prefix = prefix + pattern.substring(0, start);
|
|
384
|
-
arrayLength = tempArr.length;
|
|
385
|
-
while (i < arrayLength) {
|
|
386
|
-
newStart = after.indexOf('{');
|
|
387
|
-
if (newStart < 0) {
|
|
388
|
-
callback((prefix + tempArr[i++] + after).replace(END_WITH_EACH_REGEX, '.[]'));
|
|
389
|
-
} else {
|
|
390
|
-
dive(prefix + tempArr[i++], after, newStart, callback);
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
const AFTER_OBSERVERS = ':change';
|
|
396
|
-
function changeEvent(keyName) {
|
|
397
|
-
return keyName + AFTER_OBSERVERS;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
/**
|
|
401
|
-
@module @ember/object
|
|
402
|
-
*/
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
/*
|
|
406
|
-
The event system uses a series of nested hashes to store listeners on an
|
|
407
|
-
object. When a listener is registered, or when an event arrives, these
|
|
408
|
-
hashes are consulted to determine which target and action pair to invoke.
|
|
409
|
-
|
|
410
|
-
The hashes are stored in the object's meta hash, and look like this:
|
|
411
|
-
|
|
412
|
-
// Object's meta hash
|
|
413
|
-
{
|
|
414
|
-
listeners: { // variable name: `listenerSet`
|
|
415
|
-
"foo:change": [ // variable name: `actions`
|
|
416
|
-
target, method, once
|
|
417
|
-
]
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
*/
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
Add an event listener
|
|
425
|
-
|
|
426
|
-
@method addListener
|
|
427
|
-
@static
|
|
428
|
-
@for @ember/object/events
|
|
429
|
-
@param obj
|
|
430
|
-
@param {String} eventName
|
|
431
|
-
@param {Object|Function} target A target object or a function
|
|
432
|
-
@param {Function|String} method A function or the name of a function to be called on `target`
|
|
433
|
-
@param {Boolean} once A flag whether a function should only be called once
|
|
434
|
-
@public
|
|
435
|
-
*/
|
|
436
|
-
function addListener(obj, eventName, target, method, once, sync = true) {
|
|
437
|
-
(!(Boolean(obj) && Boolean(eventName)) && assert('You must pass at least an object and event name to addListener', Boolean(obj) && Boolean(eventName)));
|
|
438
|
-
if (!method && 'function' === typeof target) {
|
|
439
|
-
method = target;
|
|
440
|
-
target = null;
|
|
441
|
-
}
|
|
442
|
-
meta(obj).addToListeners(eventName, target, method, once === true, sync);
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
Remove an event listener
|
|
447
|
-
|
|
448
|
-
Arguments should match those passed to `addListener`.
|
|
449
|
-
|
|
450
|
-
@method removeListener
|
|
451
|
-
@static
|
|
452
|
-
@for @ember/object/events
|
|
453
|
-
@param obj
|
|
454
|
-
@param {String} eventName
|
|
455
|
-
@param {Object|Function} target A target object or a function
|
|
456
|
-
@param {Function|String} method A function or the name of a function to be called on `target`
|
|
457
|
-
@public
|
|
458
|
-
*/
|
|
459
|
-
function removeListener(obj, eventName, targetOrFunction, functionOrName) {
|
|
460
|
-
(!(Boolean(obj) && Boolean(eventName) && (typeof targetOrFunction === 'function' || typeof targetOrFunction === 'object' && Boolean(functionOrName))) && assert('You must pass at least an object, event name, and method or target and method/method name to removeListener', Boolean(obj) && Boolean(eventName) && (typeof targetOrFunction === 'function' || typeof targetOrFunction === 'object' && Boolean(functionOrName))));
|
|
461
|
-
let target, method;
|
|
462
|
-
if (typeof targetOrFunction === 'object') {
|
|
463
|
-
target = targetOrFunction;
|
|
464
|
-
method = functionOrName;
|
|
465
|
-
} else {
|
|
466
|
-
target = null;
|
|
467
|
-
method = targetOrFunction;
|
|
468
|
-
}
|
|
469
|
-
let m = meta(obj);
|
|
470
|
-
m.removeFromListeners(eventName, target, method);
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
Send an event. The execution of suspended listeners
|
|
475
|
-
is skipped, and once listeners are removed. A listener without
|
|
476
|
-
a target is executed on the passed object. If an array of actions
|
|
477
|
-
is not passed, the actions stored on the passed object are invoked.
|
|
478
|
-
|
|
479
|
-
@method sendEvent
|
|
480
|
-
@static
|
|
481
|
-
@for @ember/object/events
|
|
482
|
-
@param obj
|
|
483
|
-
@param {String} eventName
|
|
484
|
-
@param {Array} params Optional parameters for each listener.
|
|
485
|
-
@return {Boolean} if the event was delivered to one or more actions
|
|
486
|
-
@public
|
|
487
|
-
*/
|
|
488
|
-
function sendEvent(obj, eventName, params, actions, _meta) {
|
|
489
|
-
if (actions === undefined) {
|
|
490
|
-
let meta = _meta === undefined ? peekMeta(obj) : _meta;
|
|
491
|
-
actions = meta !== null ? meta.matchingListeners(eventName) : undefined;
|
|
492
|
-
}
|
|
493
|
-
if (actions === undefined || actions.length === 0) {
|
|
494
|
-
return false;
|
|
495
|
-
}
|
|
496
|
-
for (let i = actions.length - 3; i >= 0; i -= 3) {
|
|
497
|
-
// looping in reverse for once listeners
|
|
498
|
-
let target = actions[i];
|
|
499
|
-
let method = actions[i + 1];
|
|
500
|
-
let once = actions[i + 2];
|
|
501
|
-
if (!method) {
|
|
502
|
-
continue;
|
|
503
|
-
}
|
|
504
|
-
if (once) {
|
|
505
|
-
removeListener(obj, eventName, target, method);
|
|
506
|
-
}
|
|
507
|
-
if (!target) {
|
|
508
|
-
target = obj;
|
|
509
|
-
}
|
|
510
|
-
let type = typeof method;
|
|
511
|
-
if (type === 'string' || type === 'symbol') {
|
|
512
|
-
method = target[method];
|
|
513
|
-
}
|
|
514
|
-
method.apply(target, params);
|
|
515
|
-
}
|
|
516
|
-
return true;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
/**
|
|
520
|
-
@public
|
|
521
|
-
@method hasListeners
|
|
522
|
-
@static
|
|
523
|
-
@for @ember/object/events
|
|
524
|
-
@param obj
|
|
525
|
-
@param {String} eventName
|
|
526
|
-
@return {Boolean} if `obj` has listeners for event `eventName`
|
|
527
|
-
*/
|
|
528
|
-
function hasListeners(obj, eventName) {
|
|
529
|
-
let meta = peekMeta(obj);
|
|
530
|
-
if (meta === null) {
|
|
531
|
-
return false;
|
|
532
|
-
}
|
|
533
|
-
let matched = meta.matchingListeners(eventName);
|
|
534
|
-
return matched !== undefined && matched.length > 0;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
/**
|
|
538
|
-
Define a property as a function that should be executed when
|
|
539
|
-
a specified event or events are triggered.
|
|
540
|
-
|
|
541
|
-
``` javascript
|
|
542
|
-
import EmberObject from '@ember/object';
|
|
543
|
-
import { on } from '@ember/object/evented';
|
|
544
|
-
import { sendEvent } from '@ember/object/events';
|
|
545
|
-
|
|
546
|
-
let Job = EmberObject.extend({
|
|
547
|
-
logCompleted: on('completed', function() {
|
|
548
|
-
console.log('Job completed!');
|
|
549
|
-
})
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
let job = Job.create();
|
|
553
|
-
|
|
554
|
-
sendEvent(job, 'completed'); // Logs 'Job completed!'
|
|
555
|
-
```
|
|
556
|
-
|
|
557
|
-
@method on
|
|
558
|
-
@static
|
|
559
|
-
@for @ember/object/evented
|
|
560
|
-
@param {String} eventNames*
|
|
561
|
-
@param {Function} func
|
|
562
|
-
@return {Function} the listener function, passed as last argument to on(...)
|
|
563
|
-
@public
|
|
564
|
-
*/
|
|
565
|
-
function on(...args) {
|
|
566
|
-
let func = args.pop();
|
|
567
|
-
let events = args;
|
|
568
|
-
(!(typeof func === 'function') && assert('on expects function as last argument', typeof func === 'function'));
|
|
569
|
-
(!(events.length > 0 && events.every(p => typeof p === 'string' && p.length > 0)) && assert('on called without valid event names', events.length > 0 && events.every(p => typeof p === 'string' && p.length > 0)));
|
|
570
|
-
setListeners(func, events);
|
|
571
|
-
return func;
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
const SYNC_DEFAULT = !ENV._DEFAULT_ASYNC_OBSERVERS;
|
|
575
|
-
const SYNC_OBSERVERS = new Map();
|
|
576
|
-
const ASYNC_OBSERVERS = new Map();
|
|
577
|
-
|
|
578
|
-
/**
|
|
579
|
-
@module @ember/object
|
|
580
|
-
*/
|
|
581
|
-
|
|
582
|
-
/**
|
|
583
|
-
@method addObserver
|
|
584
|
-
@static
|
|
585
|
-
@for @ember/object/observers
|
|
586
|
-
@param obj
|
|
587
|
-
@param {String} path
|
|
588
|
-
@param {Object|Function} target
|
|
589
|
-
@param {Function|String} [method]
|
|
590
|
-
@public
|
|
591
|
-
*/
|
|
592
|
-
function addObserver(obj, path, target, method, sync = SYNC_DEFAULT) {
|
|
593
|
-
let eventName = changeEvent(path);
|
|
594
|
-
addListener(obj, eventName, target, method, false, sync);
|
|
595
|
-
let meta = peekMeta(obj);
|
|
596
|
-
if (meta === null || !(meta.isPrototypeMeta(obj) || meta.isInitializing())) {
|
|
597
|
-
activateObserver(obj, eventName, sync);
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
/**
|
|
602
|
-
@method removeObserver
|
|
603
|
-
@static
|
|
604
|
-
@for @ember/object/observers
|
|
605
|
-
@param obj
|
|
606
|
-
@param {String} path
|
|
607
|
-
@param {Object|Function} target
|
|
608
|
-
@param {Function|String} [method]
|
|
609
|
-
@public
|
|
610
|
-
*/
|
|
611
|
-
function removeObserver(obj, path, target, method, sync = SYNC_DEFAULT) {
|
|
612
|
-
let eventName = changeEvent(path);
|
|
613
|
-
let meta = peekMeta(obj);
|
|
614
|
-
if (meta === null || !(meta.isPrototypeMeta(obj) || meta.isInitializing())) {
|
|
615
|
-
deactivateObserver(obj, eventName, sync);
|
|
616
|
-
}
|
|
617
|
-
removeListener(obj, eventName, target, method);
|
|
618
|
-
}
|
|
619
|
-
function getOrCreateActiveObserversFor(target, sync) {
|
|
620
|
-
let observerMap = sync === true ? SYNC_OBSERVERS : ASYNC_OBSERVERS;
|
|
621
|
-
if (!observerMap.has(target)) {
|
|
622
|
-
observerMap.set(target, new Map());
|
|
623
|
-
registerDestructor(target, () => destroyObservers(target), true);
|
|
624
|
-
}
|
|
625
|
-
return observerMap.get(target);
|
|
626
|
-
}
|
|
627
|
-
function activateObserver(target, eventName, sync = false) {
|
|
628
|
-
let activeObservers = getOrCreateActiveObserversFor(target, sync);
|
|
629
|
-
if (activeObservers.has(eventName)) {
|
|
630
|
-
activeObservers.get(eventName).count++;
|
|
631
|
-
} else {
|
|
632
|
-
let path = eventName.substring(0, eventName.lastIndexOf(':'));
|
|
633
|
-
let tag = getChainTagsForKey(target, path, tagMetaFor(target), peekMeta(target));
|
|
634
|
-
activeObservers.set(eventName, {
|
|
635
|
-
count: 1,
|
|
636
|
-
path,
|
|
637
|
-
tag,
|
|
638
|
-
lastRevision: valueForTag(tag),
|
|
639
|
-
suspended: false
|
|
640
|
-
});
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
let DEACTIVATE_SUSPENDED = false;
|
|
644
|
-
let SCHEDULED_DEACTIVATE = [];
|
|
645
|
-
function deactivateObserver(target, eventName, sync = false) {
|
|
646
|
-
if (DEACTIVATE_SUSPENDED === true) {
|
|
647
|
-
SCHEDULED_DEACTIVATE.push([target, eventName, sync]);
|
|
648
|
-
return;
|
|
649
|
-
}
|
|
650
|
-
let observerMap = sync === true ? SYNC_OBSERVERS : ASYNC_OBSERVERS;
|
|
651
|
-
let activeObservers = observerMap.get(target);
|
|
652
|
-
if (activeObservers !== undefined) {
|
|
653
|
-
let observer = activeObservers.get(eventName);
|
|
654
|
-
observer.count--;
|
|
655
|
-
if (observer.count === 0) {
|
|
656
|
-
activeObservers.delete(eventName);
|
|
657
|
-
if (activeObservers.size === 0) {
|
|
658
|
-
observerMap.delete(target);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
function suspendedObserverDeactivation() {
|
|
664
|
-
DEACTIVATE_SUSPENDED = true;
|
|
665
|
-
}
|
|
666
|
-
function resumeObserverDeactivation() {
|
|
667
|
-
DEACTIVATE_SUSPENDED = false;
|
|
668
|
-
for (let [target, eventName, sync] of SCHEDULED_DEACTIVATE) {
|
|
669
|
-
deactivateObserver(target, eventName, sync);
|
|
670
|
-
}
|
|
671
|
-
SCHEDULED_DEACTIVATE = [];
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
/**
|
|
675
|
-
* Primarily used for cases where we are redefining a class, e.g. mixins/reopen
|
|
676
|
-
* being applied later. Revalidates all the observers, resetting their tags.
|
|
677
|
-
*
|
|
678
|
-
* @private
|
|
679
|
-
* @param target
|
|
680
|
-
*/
|
|
681
|
-
function revalidateObservers(target) {
|
|
682
|
-
if (ASYNC_OBSERVERS.has(target)) {
|
|
683
|
-
ASYNC_OBSERVERS.get(target).forEach(observer => {
|
|
684
|
-
observer.tag = getChainTagsForKey(target, observer.path, tagMetaFor(target), peekMeta(target));
|
|
685
|
-
observer.lastRevision = valueForTag(observer.tag);
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
if (SYNC_OBSERVERS.has(target)) {
|
|
689
|
-
SYNC_OBSERVERS.get(target).forEach(observer => {
|
|
690
|
-
observer.tag = getChainTagsForKey(target, observer.path, tagMetaFor(target), peekMeta(target));
|
|
691
|
-
observer.lastRevision = valueForTag(observer.tag);
|
|
692
|
-
});
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
let lastKnownRevision = 0;
|
|
696
|
-
function flushAsyncObservers(_schedule) {
|
|
697
|
-
let currentRevision = valueForTag(CURRENT_TAG);
|
|
698
|
-
if (lastKnownRevision === currentRevision) {
|
|
699
|
-
return;
|
|
700
|
-
}
|
|
701
|
-
lastKnownRevision = currentRevision;
|
|
702
|
-
ASYNC_OBSERVERS.forEach((activeObservers, target) => {
|
|
703
|
-
let meta = peekMeta(target);
|
|
704
|
-
activeObservers.forEach((observer, eventName) => {
|
|
705
|
-
if (!validateTag(observer.tag, observer.lastRevision)) {
|
|
706
|
-
let sendObserver = () => {
|
|
707
|
-
try {
|
|
708
|
-
sendEvent(target, eventName, [target, observer.path], undefined, meta);
|
|
709
|
-
} finally {
|
|
710
|
-
observer.tag = getChainTagsForKey(target, observer.path, tagMetaFor(target), peekMeta(target));
|
|
711
|
-
observer.lastRevision = valueForTag(observer.tag);
|
|
712
|
-
}
|
|
713
|
-
};
|
|
714
|
-
if (_schedule) {
|
|
715
|
-
_schedule('actions', sendObserver);
|
|
716
|
-
} else {
|
|
717
|
-
sendObserver();
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
});
|
|
721
|
-
});
|
|
722
|
-
}
|
|
723
|
-
function flushSyncObservers() {
|
|
724
|
-
// When flushing synchronous observers, we know that something has changed (we
|
|
725
|
-
// only do this during a notifyPropertyChange), so there's no reason to check
|
|
726
|
-
// a global revision.
|
|
727
|
-
|
|
728
|
-
SYNC_OBSERVERS.forEach((activeObservers, target) => {
|
|
729
|
-
let meta = peekMeta(target);
|
|
730
|
-
activeObservers.forEach((observer, eventName) => {
|
|
731
|
-
if (!observer.suspended && !validateTag(observer.tag, observer.lastRevision)) {
|
|
732
|
-
try {
|
|
733
|
-
observer.suspended = true;
|
|
734
|
-
sendEvent(target, eventName, [target, observer.path], undefined, meta);
|
|
735
|
-
} finally {
|
|
736
|
-
observer.tag = getChainTagsForKey(target, observer.path, tagMetaFor(target), peekMeta(target));
|
|
737
|
-
observer.lastRevision = valueForTag(observer.tag);
|
|
738
|
-
observer.suspended = false;
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
});
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
function setObserverSuspended(target, property, suspended) {
|
|
745
|
-
let activeObservers = SYNC_OBSERVERS.get(target);
|
|
746
|
-
if (!activeObservers) {
|
|
747
|
-
return;
|
|
748
|
-
}
|
|
749
|
-
let observer = activeObservers.get(changeEvent(property));
|
|
750
|
-
if (observer) {
|
|
751
|
-
observer.suspended = suspended;
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
function destroyObservers(target) {
|
|
755
|
-
if (SYNC_OBSERVERS.size > 0) SYNC_OBSERVERS.delete(target);
|
|
756
|
-
if (ASYNC_OBSERVERS.size > 0) ASYNC_OBSERVERS.delete(target);
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
/**
|
|
760
|
-
@module ember
|
|
761
|
-
@private
|
|
762
|
-
*/
|
|
763
|
-
|
|
764
|
-
const PROPERTY_DID_CHANGE = Symbol('PROPERTY_DID_CHANGE');
|
|
765
|
-
function hasPropertyDidChange(obj) {
|
|
766
|
-
return obj != null && typeof obj === 'object' && typeof obj[PROPERTY_DID_CHANGE] === 'function';
|
|
767
|
-
}
|
|
768
|
-
let deferred = 0;
|
|
769
|
-
|
|
770
|
-
/**
|
|
771
|
-
This function is called just after an object property has changed.
|
|
772
|
-
It will notify any observers and clear caches among other things.
|
|
773
|
-
|
|
774
|
-
Normally you will not need to call this method directly but if for some
|
|
775
|
-
reason you can't directly watch a property you can invoke this method
|
|
776
|
-
manually.
|
|
777
|
-
|
|
778
|
-
@method notifyPropertyChange
|
|
779
|
-
@for @ember/object
|
|
780
|
-
@param {Object} obj The object with the property that will change
|
|
781
|
-
@param {String} keyName The property key (or path) that will change.
|
|
782
|
-
@param {Meta} [_meta] The objects meta.
|
|
783
|
-
@param {unknown} [value] The new value to set for the property
|
|
784
|
-
@return {void}
|
|
785
|
-
@since 3.1.0
|
|
786
|
-
@public
|
|
787
|
-
*/
|
|
788
|
-
function notifyPropertyChange(obj, keyName, _meta, value) {
|
|
789
|
-
let meta = _meta === undefined ? peekMeta(obj) : _meta;
|
|
790
|
-
if (meta !== null && (meta.isInitializing() || meta.isPrototypeMeta(obj))) {
|
|
791
|
-
return;
|
|
792
|
-
}
|
|
793
|
-
markObjectAsDirty(obj, keyName);
|
|
794
|
-
if (deferred <= 0) {
|
|
795
|
-
flushSyncObservers();
|
|
796
|
-
}
|
|
797
|
-
if (PROPERTY_DID_CHANGE in obj) {
|
|
798
|
-
// It's redundant to do this here, but we don't want to check above so we can avoid an extra function call in prod.
|
|
799
|
-
(!(hasPropertyDidChange(obj)) && assert('property did change hook is invalid', hasPropertyDidChange(obj))); // we need to check the arguments length here; there's a check in Component's `PROPERTY_DID_CHANGE`
|
|
800
|
-
// that checks its arguments length, so we have to explicitly not call this with `value`
|
|
801
|
-
// if it is not passed to `notifyPropertyChange`
|
|
802
|
-
if (arguments.length === 4) {
|
|
803
|
-
obj[PROPERTY_DID_CHANGE](keyName, value);
|
|
804
|
-
} else {
|
|
805
|
-
obj[PROPERTY_DID_CHANGE](keyName);
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
/**
|
|
811
|
-
@method beginPropertyChanges
|
|
812
|
-
@chainable
|
|
813
|
-
@private
|
|
814
|
-
*/
|
|
815
|
-
function beginPropertyChanges() {
|
|
816
|
-
deferred++;
|
|
817
|
-
suspendedObserverDeactivation();
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
/**
|
|
821
|
-
@method endPropertyChanges
|
|
822
|
-
@private
|
|
823
|
-
*/
|
|
824
|
-
function endPropertyChanges() {
|
|
825
|
-
deferred--;
|
|
826
|
-
if (deferred <= 0) {
|
|
827
|
-
flushSyncObservers();
|
|
828
|
-
resumeObserverDeactivation();
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
/**
|
|
833
|
-
Make a series of property changes together in an
|
|
834
|
-
exception-safe way.
|
|
835
|
-
|
|
836
|
-
```javascript
|
|
837
|
-
Ember.changeProperties(function() {
|
|
838
|
-
obj1.set('foo', mayBlowUpWhenSet);
|
|
839
|
-
obj2.set('bar', baz);
|
|
840
|
-
});
|
|
841
|
-
```
|
|
842
|
-
|
|
843
|
-
@method changeProperties
|
|
844
|
-
@param {Function} callback
|
|
845
|
-
@private
|
|
846
|
-
*/
|
|
847
|
-
function changeProperties(callback) {
|
|
848
|
-
beginPropertyChanges();
|
|
849
|
-
try {
|
|
850
|
-
callback();
|
|
851
|
-
} finally {
|
|
852
|
-
endPropertyChanges();
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
/**
|
|
857
|
-
@module @ember/object
|
|
858
|
-
*/
|
|
859
|
-
|
|
860
|
-
const DEEP_EACH_REGEX = /\.@each\.[^.]+\./;
|
|
861
|
-
function noop() {}
|
|
862
|
-
/**
|
|
863
|
-
`@computed` is a decorator that turns a JavaScript getter and setter into a
|
|
864
|
-
computed property, which is a _cached, trackable value_. By default the getter
|
|
865
|
-
will only be called once and the result will be cached. You can specify
|
|
866
|
-
various properties that your computed property depends on. This will force the
|
|
867
|
-
cached result to be cleared if the dependencies are modified, and lazily recomputed the next time something asks for it.
|
|
868
|
-
|
|
869
|
-
In the following example we decorate a getter - `fullName` - by calling
|
|
870
|
-
`computed` with the property dependencies (`firstName` and `lastName`) as
|
|
871
|
-
arguments. The `fullName` getter will be called once (regardless of how many
|
|
872
|
-
times it is accessed) as long as its dependencies do not change. Once
|
|
873
|
-
`firstName` or `lastName` are updated any future calls to `fullName` will
|
|
874
|
-
incorporate the new values, and any watchers of the value such as templates
|
|
875
|
-
will be updated:
|
|
876
|
-
|
|
877
|
-
```javascript
|
|
878
|
-
import { computed, set } from '@ember/object';
|
|
879
|
-
|
|
880
|
-
class Person {
|
|
881
|
-
constructor(firstName, lastName) {
|
|
882
|
-
set(this, 'firstName', firstName);
|
|
883
|
-
set(this, 'lastName', lastName);
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
@computed('firstName', 'lastName')
|
|
887
|
-
get fullName() {
|
|
888
|
-
return `${this.firstName} ${this.lastName}`;
|
|
889
|
-
}
|
|
890
|
-
});
|
|
891
|
-
|
|
892
|
-
let tom = new Person('Tom', 'Dale');
|
|
893
|
-
|
|
894
|
-
tom.fullName; // 'Tom Dale'
|
|
895
|
-
```
|
|
896
|
-
|
|
897
|
-
You can also provide a setter, which will be used when updating the computed
|
|
898
|
-
property. Ember's `set` function must be used to update the property
|
|
899
|
-
since it will also notify observers of the property:
|
|
900
|
-
|
|
901
|
-
```javascript
|
|
902
|
-
import { computed, set } from '@ember/object';
|
|
903
|
-
|
|
904
|
-
class Person {
|
|
905
|
-
constructor(firstName, lastName) {
|
|
906
|
-
set(this, 'firstName', firstName);
|
|
907
|
-
set(this, 'lastName', lastName);
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
@computed('firstName', 'lastName')
|
|
911
|
-
get fullName() {
|
|
912
|
-
return `${this.firstName} ${this.lastName}`;
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
set fullName(value) {
|
|
916
|
-
let [firstName, lastName] = value.split(' ');
|
|
917
|
-
|
|
918
|
-
set(this, 'firstName', firstName);
|
|
919
|
-
set(this, 'lastName', lastName);
|
|
920
|
-
}
|
|
921
|
-
});
|
|
922
|
-
|
|
923
|
-
let person = new Person();
|
|
924
|
-
|
|
925
|
-
set(person, 'fullName', 'Peter Wagenet');
|
|
926
|
-
person.firstName; // 'Peter'
|
|
927
|
-
person.lastName; // 'Wagenet'
|
|
928
|
-
```
|
|
929
|
-
|
|
930
|
-
You can also pass a getter function or object with `get` and `set` functions
|
|
931
|
-
as the last argument to the computed decorator. This allows you to define
|
|
932
|
-
computed property _macros_:
|
|
933
|
-
|
|
934
|
-
```js
|
|
935
|
-
import { computed } from '@ember/object';
|
|
936
|
-
|
|
937
|
-
function join(...keys) {
|
|
938
|
-
return computed(...keys, function() {
|
|
939
|
-
return keys.map(key => this[key]).join(' ');
|
|
940
|
-
});
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
class Person {
|
|
944
|
-
@join('firstName', 'lastName')
|
|
945
|
-
fullName;
|
|
946
|
-
}
|
|
947
|
-
```
|
|
948
|
-
|
|
949
|
-
Note that when defined this way, getters and setters receive the _key_ of the
|
|
950
|
-
property they are decorating as the first argument. Setters receive the value
|
|
951
|
-
they are setting to as the second argument instead. Additionally, setters must
|
|
952
|
-
_return_ the value that should be cached:
|
|
953
|
-
|
|
954
|
-
```javascript
|
|
955
|
-
import { computed, set } from '@ember/object';
|
|
956
|
-
|
|
957
|
-
function fullNameMacro(firstNameKey, lastNameKey) {
|
|
958
|
-
return computed(firstNameKey, lastNameKey, {
|
|
959
|
-
get() {
|
|
960
|
-
return `${this[firstNameKey]} ${this[lastNameKey]}`;
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
set(key, value) {
|
|
964
|
-
let [firstName, lastName] = value.split(' ');
|
|
965
|
-
|
|
966
|
-
set(this, firstNameKey, firstName);
|
|
967
|
-
set(this, lastNameKey, lastName);
|
|
968
|
-
|
|
969
|
-
return value;
|
|
970
|
-
}
|
|
971
|
-
});
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
class Person {
|
|
975
|
-
constructor(firstName, lastName) {
|
|
976
|
-
set(this, 'firstName', firstName);
|
|
977
|
-
set(this, 'lastName', lastName);
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
@fullNameMacro('firstName', 'lastName') fullName;
|
|
981
|
-
});
|
|
982
|
-
|
|
983
|
-
let person = new Person();
|
|
984
|
-
|
|
985
|
-
set(person, 'fullName', 'Peter Wagenet');
|
|
986
|
-
person.firstName; // 'Peter'
|
|
987
|
-
person.lastName; // 'Wagenet'
|
|
988
|
-
```
|
|
989
|
-
|
|
990
|
-
Computed properties can also be used in classic classes. To do this, we
|
|
991
|
-
provide the getter and setter as the last argument like we would for a macro,
|
|
992
|
-
and we assign it to a property on the class definition. This is an _anonymous_
|
|
993
|
-
computed macro:
|
|
994
|
-
|
|
995
|
-
```javascript
|
|
996
|
-
import EmberObject, { computed, set } from '@ember/object';
|
|
997
|
-
|
|
998
|
-
let Person = EmberObject.extend({
|
|
999
|
-
// these will be supplied by `create`
|
|
1000
|
-
firstName: null,
|
|
1001
|
-
lastName: null,
|
|
1002
|
-
|
|
1003
|
-
fullName: computed('firstName', 'lastName', {
|
|
1004
|
-
get() {
|
|
1005
|
-
return `${this.firstName} ${this.lastName}`;
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
set(key, value) {
|
|
1009
|
-
let [firstName, lastName] = value.split(' ');
|
|
1010
|
-
|
|
1011
|
-
set(this, 'firstName', firstName);
|
|
1012
|
-
set(this, 'lastName', lastName);
|
|
1013
|
-
|
|
1014
|
-
return value;
|
|
1015
|
-
}
|
|
1016
|
-
})
|
|
1017
|
-
});
|
|
1018
|
-
|
|
1019
|
-
let tom = Person.create({
|
|
1020
|
-
firstName: 'Tom',
|
|
1021
|
-
lastName: 'Dale'
|
|
1022
|
-
});
|
|
1023
|
-
|
|
1024
|
-
tom.get('fullName') // 'Tom Dale'
|
|
1025
|
-
```
|
|
1026
|
-
|
|
1027
|
-
You can overwrite computed property without setters with a normal property (no
|
|
1028
|
-
longer computed) that won't change if dependencies change. You can also mark
|
|
1029
|
-
computed property as `.readOnly()` and block all attempts to set it.
|
|
1030
|
-
|
|
1031
|
-
```javascript
|
|
1032
|
-
import { computed, set } from '@ember/object';
|
|
1033
|
-
|
|
1034
|
-
class Person {
|
|
1035
|
-
constructor(firstName, lastName) {
|
|
1036
|
-
set(this, 'firstName', firstName);
|
|
1037
|
-
set(this, 'lastName', lastName);
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
@computed('firstName', 'lastName').readOnly()
|
|
1041
|
-
get fullName() {
|
|
1042
|
-
return `${this.firstName} ${this.lastName}`;
|
|
1043
|
-
}
|
|
1044
|
-
});
|
|
1045
|
-
|
|
1046
|
-
let person = new Person();
|
|
1047
|
-
person.set('fullName', 'Peter Wagenet'); // Uncaught Error: Cannot set read-only property "fullName" on object: <(...):emberXXX>
|
|
1048
|
-
```
|
|
1049
|
-
|
|
1050
|
-
Additional resources:
|
|
1051
|
-
- [Decorators RFC](https://github.com/emberjs/rfcs/blob/master/text/0408-decorators.md)
|
|
1052
|
-
- [New CP syntax RFC](https://github.com/emberjs/rfcs/blob/master/text/0011-improved-cp-syntax.md)
|
|
1053
|
-
- [New computed syntax explained in "Ember 1.12 released" ](https://emberjs.com/blog/2015/05/13/ember-1-12-released.html#toc_new-computed-syntax)
|
|
1054
|
-
|
|
1055
|
-
@class ComputedProperty
|
|
1056
|
-
@public
|
|
1057
|
-
*/
|
|
1058
|
-
class ComputedProperty extends ComputedDescriptor {
|
|
1059
|
-
_readOnly = false;
|
|
1060
|
-
_hasConfig = false;
|
|
1061
|
-
_getter = undefined;
|
|
1062
|
-
_setter = undefined;
|
|
1063
|
-
constructor(args) {
|
|
1064
|
-
super();
|
|
1065
|
-
let maybeConfig = args[args.length - 1];
|
|
1066
|
-
if (typeof maybeConfig === 'function' || maybeConfig !== null && typeof maybeConfig === 'object') {
|
|
1067
|
-
this._hasConfig = true;
|
|
1068
|
-
let config = args.pop();
|
|
1069
|
-
if (typeof config === 'function') {
|
|
1070
|
-
(!(!isClassicDecorator(config)) && assert(`You attempted to pass a computed property instance to computed(). Computed property instances are decorator functions, and cannot be passed to computed() because they cannot be turned into decorators twice`, !isClassicDecorator(config)));
|
|
1071
|
-
this._getter = config;
|
|
1072
|
-
} else {
|
|
1073
|
-
const objectConfig = config;
|
|
1074
|
-
(!(typeof objectConfig === 'object' && !Array.isArray(objectConfig)) && assert('computed expects a function or an object as last argument.', typeof objectConfig === 'object' && !Array.isArray(objectConfig)));
|
|
1075
|
-
(!(Object.keys(objectConfig).every(key => key === 'get' || key === 'set')) && assert('Config object passed to computed can only contain `get` and `set` keys.', Object.keys(objectConfig).every(key => key === 'get' || key === 'set')));
|
|
1076
|
-
(!(Boolean(objectConfig.get) || Boolean(objectConfig.set)) && assert('Computed properties must receive a getter or a setter, you passed none.', Boolean(objectConfig.get) || Boolean(objectConfig.set)));
|
|
1077
|
-
this._getter = objectConfig.get || noop;
|
|
1078
|
-
this._setter = objectConfig.set;
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
if (args.length > 0) {
|
|
1082
|
-
this._property(...args);
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
setup(obj, keyName, propertyDesc, meta) {
|
|
1086
|
-
super.setup(obj, keyName, propertyDesc, meta);
|
|
1087
|
-
(!(!(propertyDesc && typeof propertyDesc.value === 'function')) && assert(`@computed can only be used on accessors or fields, attempted to use it with ${keyName} but that was a method. Try converting it to a getter (e.g. \`get ${keyName}() {}\`)`, !(propertyDesc && typeof propertyDesc.value === 'function')));
|
|
1088
|
-
(!(!propertyDesc || !propertyDesc.initializer) && assert(`@computed can only be used on empty fields. ${keyName} has an initial value (e.g. \`${keyName} = someValue\`)`, !propertyDesc || !propertyDesc.initializer));
|
|
1089
|
-
(!(!(this._hasConfig && propertyDesc && (typeof propertyDesc.get === 'function' || typeof propertyDesc.set === 'function'))) && assert(`Attempted to apply a computed property that already has a getter/setter to a ${keyName}, but it is a method or an accessor. If you passed @computed a function or getter/setter (e.g. \`@computed({ get() { ... } })\`), then it must be applied to a field`, !(this._hasConfig && propertyDesc && (typeof propertyDesc.get === 'function' || typeof propertyDesc.set === 'function'))));
|
|
1090
|
-
if (this._hasConfig === false) {
|
|
1091
|
-
(!(propertyDesc && (typeof propertyDesc.get === 'function' || typeof propertyDesc.set === 'function')) && assert(`Attempted to use @computed on ${keyName}, but it did not have a getter or a setter. You must either pass a get a function or getter/setter to @computed directly (e.g. \`@computed({ get() { ... } })\`) or apply @computed directly to a getter/setter`, propertyDesc && (typeof propertyDesc.get === 'function' || typeof propertyDesc.set === 'function')));
|
|
1092
|
-
let {
|
|
1093
|
-
get,
|
|
1094
|
-
set
|
|
1095
|
-
} = propertyDesc;
|
|
1096
|
-
if (get !== undefined) {
|
|
1097
|
-
this._getter = get;
|
|
1098
|
-
}
|
|
1099
|
-
if (set !== undefined) {
|
|
1100
|
-
this._setter = function setterWrapper(_key, value) {
|
|
1101
|
-
let ret = set.call(this, value);
|
|
1102
|
-
if (get !== undefined) {
|
|
1103
|
-
return typeof ret === 'undefined' ? get.call(this) : ret;
|
|
1104
|
-
}
|
|
1105
|
-
return ret;
|
|
1106
|
-
};
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
_property(...passedArgs) {
|
|
1111
|
-
let args = [];
|
|
1112
|
-
function addArg(property) {
|
|
1113
|
-
(!(DEEP_EACH_REGEX.test(property) === false) && assert(`Dependent keys containing @each only work one level deep. ` + `You used the key "${property}" which is invalid. ` + `Please create an intermediary computed property or ` + `switch to using tracked properties.`, DEEP_EACH_REGEX.test(property) === false));
|
|
1114
|
-
args.push(property);
|
|
1115
|
-
}
|
|
1116
|
-
for (let arg of passedArgs) {
|
|
1117
|
-
expandProperties(arg, addArg);
|
|
1118
|
-
}
|
|
1119
|
-
this._dependentKeys = args;
|
|
1120
|
-
}
|
|
1121
|
-
get(obj, keyName) {
|
|
1122
|
-
let meta$1 = meta(obj);
|
|
1123
|
-
let tagMeta = tagMetaFor(obj);
|
|
1124
|
-
let propertyTag = tagFor(obj, keyName, tagMeta);
|
|
1125
|
-
let ret;
|
|
1126
|
-
let revision = meta$1.revisionFor(keyName);
|
|
1127
|
-
if (revision !== undefined && validateTag(propertyTag, revision)) {
|
|
1128
|
-
ret = meta$1.valueFor(keyName);
|
|
1129
|
-
} else {
|
|
1130
|
-
// For backwards compatibility, we only throw if the CP has any dependencies. CPs without dependencies
|
|
1131
|
-
// should be allowed, even after the object has been destroyed, which is why we check _dependentKeys.
|
|
1132
|
-
(!(this._dependentKeys === undefined || !isDestroyed(obj)) && assert(`Attempted to access the computed ${obj}.${keyName} on a destroyed object, which is not allowed`, this._dependentKeys === undefined || !isDestroyed(obj)));
|
|
1133
|
-
let {
|
|
1134
|
-
_getter,
|
|
1135
|
-
_dependentKeys
|
|
1136
|
-
} = this;
|
|
1137
|
-
|
|
1138
|
-
// Create a tracker that absorbs any trackable actions inside the CP
|
|
1139
|
-
untrack(() => {
|
|
1140
|
-
ret = _getter.call(obj, keyName);
|
|
1141
|
-
});
|
|
1142
|
-
if (_dependentKeys !== undefined) {
|
|
1143
|
-
UPDATE_TAG(propertyTag, getChainTagsForKeys(obj, _dependentKeys, tagMeta, meta$1));
|
|
1144
|
-
{
|
|
1145
|
-
ALLOW_CYCLES.set(propertyTag, true);
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
meta$1.setValueFor(keyName, ret);
|
|
1149
|
-
meta$1.setRevisionFor(keyName, valueForTag(propertyTag));
|
|
1150
|
-
finishLazyChains(meta$1, keyName, ret);
|
|
1151
|
-
}
|
|
1152
|
-
consumeTag(propertyTag);
|
|
1153
|
-
|
|
1154
|
-
// Add the tag of the returned value if it is an array, since arrays
|
|
1155
|
-
// should always cause updates if they are consumed and then changed
|
|
1156
|
-
if (Array.isArray(ret)) {
|
|
1157
|
-
consumeTag(tagFor(ret, '[]'));
|
|
1158
|
-
}
|
|
1159
|
-
return ret;
|
|
1160
|
-
}
|
|
1161
|
-
set(obj, keyName, value) {
|
|
1162
|
-
if (this._readOnly) {
|
|
1163
|
-
this._throwReadOnlyError(obj, keyName);
|
|
1164
|
-
}
|
|
1165
|
-
(!(this._setter !== undefined) && assert(`Cannot override the computed property \`${keyName}\` on ${toString(obj)}.`, this._setter !== undefined));
|
|
1166
|
-
let meta$1 = meta(obj);
|
|
1167
|
-
|
|
1168
|
-
// ensure two way binding works when the component has defined a computed
|
|
1169
|
-
// property with both a setter and dependent keys, in that scenario without
|
|
1170
|
-
// the sync observer added below the caller's value will never be updated
|
|
1171
|
-
//
|
|
1172
|
-
// See GH#18147 / GH#19028 for details.
|
|
1173
|
-
if (
|
|
1174
|
-
// ensure that we only run this once, while the component is being instantiated
|
|
1175
|
-
meta$1.isInitializing() && this._dependentKeys !== undefined && this._dependentKeys.length > 0 && typeof obj[PROPERTY_DID_CHANGE] === 'function' && obj.isComponent) {
|
|
1176
|
-
// It's redundant to do this here, but we don't want to check above so we can avoid an extra function call in prod.
|
|
1177
|
-
(!(hasPropertyDidChange(obj)) && assert('property did change hook is invalid', hasPropertyDidChange(obj)));
|
|
1178
|
-
addObserver(obj, keyName, () => {
|
|
1179
|
-
obj[PROPERTY_DID_CHANGE](keyName);
|
|
1180
|
-
}, undefined, true);
|
|
1181
|
-
}
|
|
1182
|
-
let ret;
|
|
1183
|
-
try {
|
|
1184
|
-
beginPropertyChanges();
|
|
1185
|
-
ret = this._set(obj, keyName, value, meta$1);
|
|
1186
|
-
finishLazyChains(meta$1, keyName, ret);
|
|
1187
|
-
let tagMeta = tagMetaFor(obj);
|
|
1188
|
-
let propertyTag = tagFor(obj, keyName, tagMeta);
|
|
1189
|
-
let {
|
|
1190
|
-
_dependentKeys
|
|
1191
|
-
} = this;
|
|
1192
|
-
if (_dependentKeys !== undefined) {
|
|
1193
|
-
UPDATE_TAG(propertyTag, getChainTagsForKeys(obj, _dependentKeys, tagMeta, meta$1));
|
|
1194
|
-
if (true /* DEBUG */) {
|
|
1195
|
-
ALLOW_CYCLES.set(propertyTag, true);
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
meta$1.setRevisionFor(keyName, valueForTag(propertyTag));
|
|
1199
|
-
} finally {
|
|
1200
|
-
endPropertyChanges();
|
|
1201
|
-
}
|
|
1202
|
-
return ret;
|
|
1203
|
-
}
|
|
1204
|
-
_throwReadOnlyError(obj, keyName) {
|
|
1205
|
-
throw new Error(`Cannot set read-only property "${keyName}" on object: ${inspect(obj)}`);
|
|
1206
|
-
}
|
|
1207
|
-
_set(obj, keyName, value, meta) {
|
|
1208
|
-
let hadCachedValue = meta.revisionFor(keyName) !== undefined;
|
|
1209
|
-
let cachedValue = meta.valueFor(keyName);
|
|
1210
|
-
let ret;
|
|
1211
|
-
let {
|
|
1212
|
-
_setter
|
|
1213
|
-
} = this;
|
|
1214
|
-
setObserverSuspended(obj, keyName, true);
|
|
1215
|
-
try {
|
|
1216
|
-
ret = _setter.call(obj, keyName, value, cachedValue);
|
|
1217
|
-
} finally {
|
|
1218
|
-
setObserverSuspended(obj, keyName, false);
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
// allows setter to return the same value that is cached already
|
|
1222
|
-
if (hadCachedValue && cachedValue === ret) {
|
|
1223
|
-
return ret;
|
|
1224
|
-
}
|
|
1225
|
-
meta.setValueFor(keyName, ret);
|
|
1226
|
-
notifyPropertyChange(obj, keyName, meta, value);
|
|
1227
|
-
return ret;
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
/* called before property is overridden */
|
|
1231
|
-
teardown(obj, keyName, meta) {
|
|
1232
|
-
if (meta.revisionFor(keyName) !== undefined) {
|
|
1233
|
-
meta.setRevisionFor(keyName, undefined);
|
|
1234
|
-
meta.setValueFor(keyName, undefined);
|
|
1235
|
-
}
|
|
1236
|
-
super.teardown(obj, keyName, meta);
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
class AutoComputedProperty extends ComputedProperty {
|
|
1240
|
-
get(obj, keyName) {
|
|
1241
|
-
let meta$1 = meta(obj);
|
|
1242
|
-
let tagMeta = tagMetaFor(obj);
|
|
1243
|
-
let propertyTag = tagFor(obj, keyName, tagMeta);
|
|
1244
|
-
let ret;
|
|
1245
|
-
let revision = meta$1.revisionFor(keyName);
|
|
1246
|
-
if (revision !== undefined && validateTag(propertyTag, revision)) {
|
|
1247
|
-
ret = meta$1.valueFor(keyName);
|
|
1248
|
-
} else {
|
|
1249
|
-
(!(!isDestroyed(obj)) && assert(`Attempted to access the computed ${obj}.${keyName} on a destroyed object, which is not allowed`, !isDestroyed(obj)));
|
|
1250
|
-
let {
|
|
1251
|
-
_getter
|
|
1252
|
-
} = this;
|
|
1253
|
-
|
|
1254
|
-
// Create a tracker that absorbs any trackable actions inside the CP
|
|
1255
|
-
let tag = track(() => {
|
|
1256
|
-
ret = _getter.call(obj, keyName);
|
|
1257
|
-
});
|
|
1258
|
-
UPDATE_TAG(propertyTag, tag);
|
|
1259
|
-
meta$1.setValueFor(keyName, ret);
|
|
1260
|
-
meta$1.setRevisionFor(keyName, valueForTag(propertyTag));
|
|
1261
|
-
finishLazyChains(meta$1, keyName, ret);
|
|
1262
|
-
}
|
|
1263
|
-
consumeTag(propertyTag);
|
|
1264
|
-
|
|
1265
|
-
// Add the tag of the returned value if it is an array, since arrays
|
|
1266
|
-
// should always cause updates if they are consumed and then changed
|
|
1267
|
-
if (Array.isArray(ret)) {
|
|
1268
|
-
consumeTag(tagFor(ret, '[]', tagMeta));
|
|
1269
|
-
}
|
|
1270
|
-
return ret;
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
// TODO: This class can be svelted once `meta` has been deprecated
|
|
1274
|
-
class ComputedDecoratorImpl extends Function {
|
|
1275
|
-
/**
|
|
1276
|
-
Call on a computed property to set it into read-only mode. When in this
|
|
1277
|
-
mode the computed property will throw an error when set.
|
|
1278
|
-
Example:
|
|
1279
|
-
```javascript
|
|
1280
|
-
import { computed, set } from '@ember/object';
|
|
1281
|
-
class Person {
|
|
1282
|
-
@computed().readOnly()
|
|
1283
|
-
get guid() {
|
|
1284
|
-
return 'guid-guid-guid';
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
let person = new Person();
|
|
1288
|
-
set(person, 'guid', 'new-guid'); // will throw an exception
|
|
1289
|
-
```
|
|
1290
|
-
Classic Class Example:
|
|
1291
|
-
```javascript
|
|
1292
|
-
import EmberObject, { computed } from '@ember/object';
|
|
1293
|
-
let Person = EmberObject.extend({
|
|
1294
|
-
guid: computed(function() {
|
|
1295
|
-
return 'guid-guid-guid';
|
|
1296
|
-
}).readOnly()
|
|
1297
|
-
});
|
|
1298
|
-
let person = Person.create();
|
|
1299
|
-
person.set('guid', 'new-guid'); // will throw an exception
|
|
1300
|
-
```
|
|
1301
|
-
@method readOnly
|
|
1302
|
-
@return {ComputedProperty} this
|
|
1303
|
-
@chainable
|
|
1304
|
-
@public
|
|
1305
|
-
*/
|
|
1306
|
-
readOnly() {
|
|
1307
|
-
let desc = descriptorForDecorator(this);
|
|
1308
|
-
(!(!(desc._setter && desc._setter !== desc._getter)) && assert('Computed properties that define a setter using the new syntax cannot be read-only', !(desc._setter && desc._setter !== desc._getter)));
|
|
1309
|
-
desc._readOnly = true;
|
|
1310
|
-
return this;
|
|
1311
|
-
}
|
|
1312
|
-
|
|
1313
|
-
/**
|
|
1314
|
-
In some cases, you may want to annotate computed properties with additional
|
|
1315
|
-
metadata about how they function or what values they operate on. For example,
|
|
1316
|
-
computed property functions may close over variables that are then no longer
|
|
1317
|
-
available for introspection. You can pass a hash of these values to a
|
|
1318
|
-
computed property.
|
|
1319
|
-
Example:
|
|
1320
|
-
```javascript
|
|
1321
|
-
import { computed } from '@ember/object';
|
|
1322
|
-
import Person from 'my-app/utils/person';
|
|
1323
|
-
class Store {
|
|
1324
|
-
@computed().meta({ type: Person })
|
|
1325
|
-
get person() {
|
|
1326
|
-
let personId = this.personId;
|
|
1327
|
-
return Person.create({ id: personId });
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
```
|
|
1331
|
-
Classic Class Example:
|
|
1332
|
-
```javascript
|
|
1333
|
-
import { computed } from '@ember/object';
|
|
1334
|
-
import Person from 'my-app/utils/person';
|
|
1335
|
-
const Store = EmberObject.extend({
|
|
1336
|
-
person: computed(function() {
|
|
1337
|
-
let personId = this.get('personId');
|
|
1338
|
-
return Person.create({ id: personId });
|
|
1339
|
-
}).meta({ type: Person })
|
|
1340
|
-
});
|
|
1341
|
-
```
|
|
1342
|
-
The hash that you pass to the `meta()` function will be saved on the
|
|
1343
|
-
computed property descriptor under the `_meta` key. Ember runtime
|
|
1344
|
-
exposes a public API for retrieving these values from classes,
|
|
1345
|
-
via the `metaForProperty()` function.
|
|
1346
|
-
@method meta
|
|
1347
|
-
@param {Object} meta
|
|
1348
|
-
@chainable
|
|
1349
|
-
@public
|
|
1350
|
-
*/
|
|
1351
|
-
|
|
1352
|
-
meta(meta) {
|
|
1353
|
-
let prop = descriptorForDecorator(this);
|
|
1354
|
-
if (arguments.length === 0) {
|
|
1355
|
-
return prop._meta || {};
|
|
1356
|
-
} else {
|
|
1357
|
-
prop._meta = meta;
|
|
1358
|
-
return this;
|
|
1359
|
-
}
|
|
1360
|
-
}
|
|
1361
|
-
|
|
1362
|
-
// TODO: Remove this when we can provide alternatives in the ecosystem to
|
|
1363
|
-
// addons such as ember-macro-helpers that use it.
|
|
1364
|
-
/** @internal */
|
|
1365
|
-
get _getter() {
|
|
1366
|
-
return descriptorForDecorator(this)._getter;
|
|
1367
|
-
}
|
|
1368
|
-
|
|
1369
|
-
// TODO: Refactor this, this is an internal API only
|
|
1370
|
-
/** @internal */
|
|
1371
|
-
set enumerable(value) {
|
|
1372
|
-
descriptorForDecorator(this).enumerable = value;
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
|
-
/**
|
|
1377
|
-
This helper returns a new property descriptor that wraps the passed
|
|
1378
|
-
computed property function. You can use this helper to define properties with
|
|
1379
|
-
native decorator syntax, mixins, or via `defineProperty()`.
|
|
1380
|
-
|
|
1381
|
-
Example:
|
|
1382
|
-
|
|
1383
|
-
```js
|
|
1384
|
-
import { computed, set } from '@ember/object';
|
|
1385
|
-
|
|
1386
|
-
class Person {
|
|
1387
|
-
constructor() {
|
|
1388
|
-
this.firstName = 'Betty';
|
|
1389
|
-
this.lastName = 'Jones';
|
|
1390
|
-
},
|
|
1391
|
-
|
|
1392
|
-
@computed('firstName', 'lastName')
|
|
1393
|
-
get fullName() {
|
|
1394
|
-
return `${this.firstName} ${this.lastName}`;
|
|
1395
|
-
}
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
|
-
let client = new Person();
|
|
1399
|
-
|
|
1400
|
-
client.fullName; // 'Betty Jones'
|
|
1401
|
-
|
|
1402
|
-
set(client, 'lastName', 'Fuller');
|
|
1403
|
-
client.fullName; // 'Betty Fuller'
|
|
1404
|
-
```
|
|
1405
|
-
|
|
1406
|
-
Classic Class Example:
|
|
1407
|
-
|
|
1408
|
-
```js
|
|
1409
|
-
import EmberObject, { computed } from '@ember/object';
|
|
1410
|
-
|
|
1411
|
-
let Person = EmberObject.extend({
|
|
1412
|
-
init() {
|
|
1413
|
-
this._super(...arguments);
|
|
1414
|
-
|
|
1415
|
-
this.firstName = 'Betty';
|
|
1416
|
-
this.lastName = 'Jones';
|
|
1417
|
-
},
|
|
1418
|
-
|
|
1419
|
-
fullName: computed('firstName', 'lastName', function() {
|
|
1420
|
-
return `${this.get('firstName')} ${this.get('lastName')}`;
|
|
1421
|
-
})
|
|
1422
|
-
});
|
|
1423
|
-
|
|
1424
|
-
let client = Person.create();
|
|
1425
|
-
|
|
1426
|
-
client.get('fullName'); // 'Betty Jones'
|
|
1427
|
-
|
|
1428
|
-
client.set('lastName', 'Fuller');
|
|
1429
|
-
client.get('fullName'); // 'Betty Fuller'
|
|
1430
|
-
```
|
|
1431
|
-
|
|
1432
|
-
You can also provide a setter, either directly on the class using native class
|
|
1433
|
-
syntax, or by passing a hash with `get` and `set` functions.
|
|
1434
|
-
|
|
1435
|
-
Example:
|
|
1436
|
-
|
|
1437
|
-
```js
|
|
1438
|
-
import { computed, set } from '@ember/object';
|
|
1439
|
-
|
|
1440
|
-
class Person {
|
|
1441
|
-
constructor() {
|
|
1442
|
-
this.firstName = 'Betty';
|
|
1443
|
-
this.lastName = 'Jones';
|
|
1444
|
-
},
|
|
1445
|
-
|
|
1446
|
-
@computed('firstName', 'lastName')
|
|
1447
|
-
get fullName() {
|
|
1448
|
-
return `${this.firstName} ${this.lastName}`;
|
|
1449
|
-
}
|
|
1450
|
-
|
|
1451
|
-
set fullName(value) {
|
|
1452
|
-
let [firstName, lastName] = value.split(/\s+/);
|
|
1453
|
-
|
|
1454
|
-
set(this, 'firstName', firstName);
|
|
1455
|
-
set(this, 'lastName', lastName);
|
|
1456
|
-
|
|
1457
|
-
return value;
|
|
1458
|
-
}
|
|
1459
|
-
}
|
|
1460
|
-
|
|
1461
|
-
let client = new Person();
|
|
1462
|
-
|
|
1463
|
-
client.fullName; // 'Betty Jones'
|
|
1464
|
-
|
|
1465
|
-
set(client, 'lastName', 'Fuller');
|
|
1466
|
-
client.fullName; // 'Betty Fuller'
|
|
1467
|
-
```
|
|
1468
|
-
|
|
1469
|
-
Classic Class Example:
|
|
1470
|
-
|
|
1471
|
-
```js
|
|
1472
|
-
import EmberObject, { computed } from '@ember/object';
|
|
1473
|
-
|
|
1474
|
-
let Person = EmberObject.extend({
|
|
1475
|
-
init() {
|
|
1476
|
-
this._super(...arguments);
|
|
1477
|
-
|
|
1478
|
-
this.firstName = 'Betty';
|
|
1479
|
-
this.lastName = 'Jones';
|
|
1480
|
-
},
|
|
1481
|
-
|
|
1482
|
-
fullName: computed('firstName', 'lastName', {
|
|
1483
|
-
get(key) {
|
|
1484
|
-
return `${this.get('firstName')} ${this.get('lastName')}`;
|
|
1485
|
-
},
|
|
1486
|
-
set(key, value) {
|
|
1487
|
-
let [firstName, lastName] = value.split(/\s+/);
|
|
1488
|
-
this.setProperties({ firstName, lastName });
|
|
1489
|
-
return value;
|
|
1490
|
-
}
|
|
1491
|
-
})
|
|
1492
|
-
});
|
|
1493
|
-
|
|
1494
|
-
let client = Person.create();
|
|
1495
|
-
client.get('firstName'); // 'Betty'
|
|
1496
|
-
|
|
1497
|
-
client.set('fullName', 'Carroll Fuller');
|
|
1498
|
-
client.get('firstName'); // 'Carroll'
|
|
1499
|
-
```
|
|
1500
|
-
|
|
1501
|
-
When passed as an argument, the `set` function should accept two parameters,
|
|
1502
|
-
`key` and `value`. The value returned from `set` will be the new value of the
|
|
1503
|
-
property.
|
|
1504
|
-
|
|
1505
|
-
_Note: This is the preferred way to define computed properties when writing third-party
|
|
1506
|
-
libraries that depend on or use Ember, since there is no guarantee that the user
|
|
1507
|
-
will have [prototype Extensions](https://guides.emberjs.com/release/configuring-ember/disabling-prototype-extensions/) enabled._
|
|
1508
|
-
|
|
1509
|
-
@method computed
|
|
1510
|
-
@for @ember/object
|
|
1511
|
-
@static
|
|
1512
|
-
@param {String} [dependentKeys*] Optional dependent keys that trigger this computed property.
|
|
1513
|
-
@param {Function} func The computed property function.
|
|
1514
|
-
@return {ComputedDecorator} property decorator instance
|
|
1515
|
-
@public
|
|
1516
|
-
*/
|
|
1517
|
-
// @computed without parens or computed with descriptor args
|
|
1518
|
-
|
|
1519
|
-
// @computed with keys only
|
|
1520
|
-
|
|
1521
|
-
// @computed with keys and config
|
|
1522
|
-
|
|
1523
|
-
// @computed with config only
|
|
1524
|
-
|
|
1525
|
-
function computed(...args) {
|
|
1526
|
-
(!(!(isElementDescriptor(args.slice(0, 3)) && args.length === 5 && args[4] === true)) && assert(`@computed can only be used directly as a native decorator. If you're using tracked in classic classes, add parenthesis to call it like a function: computed()`, !(isElementDescriptor(args.slice(0, 3)) && args.length === 5 && args[4] === true)));
|
|
1527
|
-
if (isElementDescriptor(args)) {
|
|
1528
|
-
// SAFETY: We passed in the impl for this class
|
|
1529
|
-
let decorator = makeComputedDecorator(new ComputedProperty([]), ComputedDecoratorImpl);
|
|
1530
|
-
return decorator(args[0], args[1], args[2]);
|
|
1531
|
-
}
|
|
1532
|
-
|
|
1533
|
-
// SAFETY: We passed in the impl for this class
|
|
1534
|
-
return makeComputedDecorator(new ComputedProperty(args), ComputedDecoratorImpl);
|
|
1535
|
-
}
|
|
1536
|
-
function autoComputed(...config) {
|
|
1537
|
-
// SAFETY: We passed in the impl for this class
|
|
1538
|
-
return makeComputedDecorator(new AutoComputedProperty(config), ComputedDecoratorImpl);
|
|
1539
|
-
}
|
|
1540
|
-
|
|
1541
|
-
/**
|
|
1542
|
-
Allows checking if a given property on an object is a computed property. For the most part,
|
|
1543
|
-
this doesn't matter (you would normally just access the property directly and use its value),
|
|
1544
|
-
but for some tooling specific scenarios (e.g. the ember-inspector) it is important to
|
|
1545
|
-
differentiate if a property is a computed property or a "normal" property.
|
|
1546
|
-
|
|
1547
|
-
This will work on either a class's prototype or an instance itself.
|
|
1548
|
-
|
|
1549
|
-
@static
|
|
1550
|
-
@method isComputed
|
|
1551
|
-
@for @ember/debug
|
|
1552
|
-
@private
|
|
1553
|
-
*/
|
|
1554
|
-
function isComputed(obj, key) {
|
|
1555
|
-
return Boolean(descriptorForProperty(obj, key));
|
|
1556
|
-
}
|
|
1557
|
-
|
|
1558
|
-
/**
|
|
1559
|
-
@module @ember/object
|
|
1560
|
-
*/
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
/**
|
|
1564
|
-
NOTE: This is a low-level method used by other parts of the API. You almost
|
|
1565
|
-
never want to call this method directly. Instead you should use
|
|
1566
|
-
`mixin()` to define new properties.
|
|
1567
|
-
|
|
1568
|
-
Defines a property on an object. This method works much like the ES5
|
|
1569
|
-
`Object.defineProperty()` method except that it can also accept computed
|
|
1570
|
-
properties and other special descriptors.
|
|
1571
|
-
|
|
1572
|
-
Normally this method takes only three parameters. However if you pass an
|
|
1573
|
-
instance of `Descriptor` as the third param then you can pass an
|
|
1574
|
-
optional value as the fourth parameter. This is often more efficient than
|
|
1575
|
-
creating new descriptor hashes for each property.
|
|
1576
|
-
|
|
1577
|
-
## Examples
|
|
1578
|
-
|
|
1579
|
-
```javascript
|
|
1580
|
-
import { defineProperty, computed } from '@ember/object';
|
|
1581
|
-
|
|
1582
|
-
// ES5 compatible mode
|
|
1583
|
-
defineProperty(contact, 'firstName', {
|
|
1584
|
-
writable: true,
|
|
1585
|
-
configurable: false,
|
|
1586
|
-
enumerable: true,
|
|
1587
|
-
value: 'Charles'
|
|
1588
|
-
});
|
|
1589
|
-
|
|
1590
|
-
// define a simple property
|
|
1591
|
-
defineProperty(contact, 'lastName', undefined, 'Jolley');
|
|
1592
|
-
|
|
1593
|
-
// define a computed property
|
|
1594
|
-
defineProperty(contact, 'fullName', computed('firstName', 'lastName', function() {
|
|
1595
|
-
return this.firstName+' '+this.lastName;
|
|
1596
|
-
}));
|
|
1597
|
-
```
|
|
1598
|
-
|
|
1599
|
-
@public
|
|
1600
|
-
@method defineProperty
|
|
1601
|
-
@static
|
|
1602
|
-
@for @ember/object
|
|
1603
|
-
@param {Object} obj the object to define this property on. This may be a prototype.
|
|
1604
|
-
@param {String} keyName the name of the property
|
|
1605
|
-
@param {Descriptor} [desc] an instance of `Descriptor` (typically a
|
|
1606
|
-
computed property) or an ES5 descriptor.
|
|
1607
|
-
You must provide this or `data` but not both.
|
|
1608
|
-
@param {*} [data] something other than a descriptor, that will
|
|
1609
|
-
become the explicit value of this property.
|
|
1610
|
-
*/
|
|
1611
|
-
function defineProperty(obj, keyName, desc, data, _meta) {
|
|
1612
|
-
let meta$1 = _meta === undefined ? meta(obj) : _meta;
|
|
1613
|
-
let previousDesc = descriptorForProperty(obj, keyName, meta$1);
|
|
1614
|
-
let wasDescriptor = previousDesc !== undefined;
|
|
1615
|
-
if (wasDescriptor) {
|
|
1616
|
-
previousDesc.teardown(obj, keyName, meta$1);
|
|
1617
|
-
}
|
|
1618
|
-
if (isClassicDecorator(desc)) {
|
|
1619
|
-
defineDecorator(obj, keyName, desc, meta$1);
|
|
1620
|
-
} else if (desc === null || desc === undefined) {
|
|
1621
|
-
defineValue(obj, keyName, data, wasDescriptor, true);
|
|
1622
|
-
} else {
|
|
1623
|
-
// fallback to ES5
|
|
1624
|
-
Object.defineProperty(obj, keyName, desc);
|
|
1625
|
-
}
|
|
1626
|
-
|
|
1627
|
-
// if key is being watched, override chains that
|
|
1628
|
-
// were initialized with the prototype
|
|
1629
|
-
if (!meta$1.isPrototypeMeta(obj)) {
|
|
1630
|
-
revalidateObservers(obj);
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
function defineDecorator(obj, keyName, desc, meta) {
|
|
1634
|
-
let propertyDesc;
|
|
1635
|
-
{
|
|
1636
|
-
propertyDesc = desc(obj, keyName, undefined, meta, true);
|
|
1637
|
-
}
|
|
1638
|
-
Object.defineProperty(obj, keyName, propertyDesc);
|
|
1639
|
-
|
|
1640
|
-
// pass the decorator function forward for backwards compat
|
|
1641
|
-
return desc;
|
|
1642
|
-
}
|
|
1643
|
-
function defineValue(obj, keyName, value, wasDescriptor, enumerable = true) {
|
|
1644
|
-
if (wasDescriptor === true || enumerable === false) {
|
|
1645
|
-
Object.defineProperty(obj, keyName, {
|
|
1646
|
-
configurable: true,
|
|
1647
|
-
enumerable,
|
|
1648
|
-
writable: true,
|
|
1649
|
-
value
|
|
1650
|
-
});
|
|
1651
|
-
} else {
|
|
1652
|
-
{
|
|
1653
|
-
setWithMandatorySetter(obj, keyName, value);
|
|
1654
|
-
}
|
|
1655
|
-
}
|
|
1656
|
-
return value;
|
|
1657
|
-
}
|
|
1658
|
-
|
|
1659
|
-
const firstDotIndexCache = new Cache(1000, key => key.indexOf('.'));
|
|
1660
|
-
function isPath(path) {
|
|
1661
|
-
return typeof path === 'string' && firstDotIndexCache.get(path) !== -1;
|
|
1662
|
-
}
|
|
1663
|
-
|
|
1664
|
-
/**
|
|
1665
|
-
@module @ember/object
|
|
1666
|
-
*/
|
|
1667
|
-
|
|
1668
|
-
const PROXY_CONTENT = Symbol('PROXY_CONTENT');
|
|
1669
|
-
let getPossibleMandatoryProxyValue;
|
|
1670
|
-
{
|
|
1671
|
-
getPossibleMandatoryProxyValue = function getPossibleMandatoryProxyValue(obj, keyName) {
|
|
1672
|
-
let content = obj[PROXY_CONTENT];
|
|
1673
|
-
if (content === undefined) {
|
|
1674
|
-
return obj[keyName];
|
|
1675
|
-
} else {
|
|
1676
|
-
/* global Reflect */
|
|
1677
|
-
return Reflect.get(content, keyName, obj);
|
|
1678
|
-
}
|
|
1679
|
-
};
|
|
1680
|
-
}
|
|
1681
|
-
function hasUnknownProperty(val) {
|
|
1682
|
-
return typeof val === 'object' && val !== null && typeof val.unknownProperty === 'function';
|
|
1683
|
-
}
|
|
1684
|
-
|
|
1685
|
-
// ..........................................................
|
|
1686
|
-
// GET AND SET
|
|
1687
|
-
//
|
|
1688
|
-
// If we are on a platform that supports accessors we can use those.
|
|
1689
|
-
// Otherwise simulate accessors by looking up the property directly on the
|
|
1690
|
-
// object.
|
|
1691
|
-
|
|
1692
|
-
/**
|
|
1693
|
-
Gets the value of a property on an object. If the property is computed,
|
|
1694
|
-
the function will be invoked. If the property is not defined but the
|
|
1695
|
-
object implements the `unknownProperty` method then that will be invoked.
|
|
1696
|
-
|
|
1697
|
-
```javascript
|
|
1698
|
-
import { get } from '@ember/object';
|
|
1699
|
-
get(obj, "name");
|
|
1700
|
-
```
|
|
1701
|
-
|
|
1702
|
-
You only need to use this method to retrieve properties if the property
|
|
1703
|
-
might not be defined on the object and you want to respect the
|
|
1704
|
-
`unknownProperty` handler. Otherwise you can access the property directly.
|
|
1705
|
-
|
|
1706
|
-
Note that if the object itself is `undefined`, this method will throw
|
|
1707
|
-
an error.
|
|
1708
|
-
|
|
1709
|
-
@method get
|
|
1710
|
-
@for @ember/object
|
|
1711
|
-
@static
|
|
1712
|
-
@param {Object} obj The object to retrieve from.
|
|
1713
|
-
@param {String} keyName The property key to retrieve
|
|
1714
|
-
@return {Object} the property value or `null`.
|
|
1715
|
-
@public
|
|
1716
|
-
*/
|
|
1717
|
-
|
|
1718
|
-
function get(obj, keyName) {
|
|
1719
|
-
(!(arguments.length === 2) && assert(`Get must be called with two arguments; an object and a property key`, arguments.length === 2));
|
|
1720
|
-
(!(obj !== undefined && obj !== null) && assert(`Cannot call get with '${keyName}' on an undefined object.`, obj !== undefined && obj !== null));
|
|
1721
|
-
(!(typeof keyName === 'string' || typeof keyName === 'number' && !isNaN(keyName)) && assert(`The key provided to get must be a string or number, you passed ${keyName}`, typeof keyName === 'string' || typeof keyName === 'number' && !isNaN(keyName)));
|
|
1722
|
-
(!(typeof keyName !== 'string' || keyName.lastIndexOf('this.', 0) !== 0) && assert(`'this' in paths is not supported`, typeof keyName !== 'string' || keyName.lastIndexOf('this.', 0) !== 0));
|
|
1723
|
-
return isPath(keyName) ? _getPath(obj, keyName) : _getProp(obj, keyName);
|
|
1724
|
-
}
|
|
1725
|
-
function _getProp(obj, keyName) {
|
|
1726
|
-
if (obj == null) {
|
|
1727
|
-
return;
|
|
1728
|
-
}
|
|
1729
|
-
let value;
|
|
1730
|
-
if (typeof obj === 'object' || typeof obj === 'function') {
|
|
1731
|
-
{
|
|
1732
|
-
value = getPossibleMandatoryProxyValue(obj, keyName);
|
|
1733
|
-
}
|
|
1734
|
-
if (value === undefined && typeof obj === 'object' && !(keyName in obj) && hasUnknownProperty(obj)) {
|
|
1735
|
-
value = obj.unknownProperty(keyName);
|
|
1736
|
-
}
|
|
1737
|
-
if (isTracking()) {
|
|
1738
|
-
consumeTag(tagFor(obj, keyName));
|
|
1739
|
-
if (Array.isArray(value) || isEmberArray(value)) {
|
|
1740
|
-
// Add the tag of the returned value if it is an array, since arrays
|
|
1741
|
-
// should always cause updates if they are consumed and then changed
|
|
1742
|
-
consumeTag(tagFor(value, '[]'));
|
|
1743
|
-
}
|
|
1744
|
-
}
|
|
1745
|
-
} else {
|
|
1746
|
-
// SAFETY: It should be ok to access properties on any non-nullish value
|
|
1747
|
-
value = obj[keyName];
|
|
1748
|
-
}
|
|
1749
|
-
return value;
|
|
1750
|
-
}
|
|
1751
|
-
function _getPath(obj, path, forSet) {
|
|
1752
|
-
let parts = typeof path === 'string' ? path.split('.') : path;
|
|
1753
|
-
for (let part of parts) {
|
|
1754
|
-
if (obj === undefined || obj === null || obj.isDestroyed) {
|
|
1755
|
-
return undefined;
|
|
1756
|
-
}
|
|
1757
|
-
if (forSet && (part === '__proto__' || part === 'constructor')) {
|
|
1758
|
-
return;
|
|
1759
|
-
}
|
|
1760
|
-
obj = _getProp(obj, part);
|
|
1761
|
-
}
|
|
1762
|
-
return obj;
|
|
1763
|
-
}
|
|
1764
|
-
|
|
1765
|
-
// Warm it up
|
|
1766
|
-
_getProp('foo', 'a');
|
|
1767
|
-
_getProp('foo', 1);
|
|
1768
|
-
_getProp({}, 'a');
|
|
1769
|
-
_getProp({}, 1);
|
|
1770
|
-
_getProp({
|
|
1771
|
-
unknownProperty() {}
|
|
1772
|
-
}, 'a');
|
|
1773
|
-
_getProp({
|
|
1774
|
-
unknownProperty() {}
|
|
1775
|
-
}, 1);
|
|
1776
|
-
get({}, 'foo');
|
|
1777
|
-
get({}, 'foo.bar');
|
|
1778
|
-
let fakeProxy = {};
|
|
1779
|
-
setProxy(fakeProxy);
|
|
1780
|
-
track(() => _getProp({}, 'a'));
|
|
1781
|
-
track(() => _getProp({}, 1));
|
|
1782
|
-
track(() => _getProp({
|
|
1783
|
-
a: []
|
|
1784
|
-
}, 'a'));
|
|
1785
|
-
track(() => _getProp({
|
|
1786
|
-
a: fakeProxy
|
|
1787
|
-
}, 'a'));
|
|
1788
|
-
|
|
1789
|
-
/**
|
|
1790
|
-
@module ember
|
|
1791
|
-
*/
|
|
1792
|
-
/**
|
|
1793
|
-
Helper class that allows you to register your library with Ember.
|
|
1794
|
-
|
|
1795
|
-
Singleton created at `Ember.libraries`.
|
|
1796
|
-
|
|
1797
|
-
@class Libraries
|
|
1798
|
-
@constructor
|
|
1799
|
-
@private
|
|
1800
|
-
*/
|
|
1801
|
-
class Libraries {
|
|
1802
|
-
_registry;
|
|
1803
|
-
_coreLibIndex;
|
|
1804
|
-
constructor() {
|
|
1805
|
-
this._registry = [];
|
|
1806
|
-
this._coreLibIndex = 0;
|
|
1807
|
-
}
|
|
1808
|
-
_getLibraryByName(name) {
|
|
1809
|
-
let libs = this._registry;
|
|
1810
|
-
for (let lib of libs) {
|
|
1811
|
-
if (lib.name === name) {
|
|
1812
|
-
return lib;
|
|
1813
|
-
}
|
|
1814
|
-
}
|
|
1815
|
-
return undefined;
|
|
1816
|
-
}
|
|
1817
|
-
register(name, version, isCoreLibrary) {
|
|
1818
|
-
let index = this._registry.length;
|
|
1819
|
-
if (!this._getLibraryByName(name)) {
|
|
1820
|
-
if (isCoreLibrary) {
|
|
1821
|
-
index = this._coreLibIndex++;
|
|
1822
|
-
}
|
|
1823
|
-
this._registry.splice(index, 0, {
|
|
1824
|
-
name,
|
|
1825
|
-
version
|
|
1826
|
-
});
|
|
1827
|
-
} else {
|
|
1828
|
-
(warn(`Library "${name}" is already registered with Ember.`, false, {
|
|
1829
|
-
id: 'ember-metal.libraries-register'
|
|
1830
|
-
}));
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
registerCoreLibrary(name, version) {
|
|
1834
|
-
this.register(name, version, true);
|
|
1835
|
-
}
|
|
1836
|
-
deRegister(name) {
|
|
1837
|
-
let lib = this._getLibraryByName(name);
|
|
1838
|
-
let index;
|
|
1839
|
-
if (lib) {
|
|
1840
|
-
index = this._registry.indexOf(lib);
|
|
1841
|
-
this._registry.splice(index, 1);
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
1844
|
-
}
|
|
1845
|
-
{
|
|
1846
|
-
Libraries.prototype.logVersions = function () {
|
|
1847
|
-
let libs = this._registry;
|
|
1848
|
-
let nameLengths = libs.map(item => get(item, 'name.length'));
|
|
1849
|
-
(!(nameLengths instanceof Array && nameLengths.every(n => typeof n === 'number')) && assert('nameLengths is number array', nameLengths instanceof Array && nameLengths.every(n => typeof n === 'number')));
|
|
1850
|
-
let maxNameLength = Math.max.apply(null, nameLengths);
|
|
1851
|
-
debug('-------------------------------');
|
|
1852
|
-
for (let lib of libs) {
|
|
1853
|
-
let spaces = new Array(maxNameLength - lib.name.length + 1).join(' ');
|
|
1854
|
-
debug([lib.name, spaces, ' : ', lib.version].join(''));
|
|
1855
|
-
}
|
|
1856
|
-
debug('-------------------------------');
|
|
1857
|
-
};
|
|
1858
|
-
}
|
|
1859
|
-
const LIBRARIES = new Libraries();
|
|
1860
|
-
LIBRARIES.registerCoreLibrary('Ember', VERSION);
|
|
1861
|
-
|
|
1862
|
-
let DEBUG_INJECTION_FUNCTIONS;
|
|
1863
|
-
{
|
|
1864
|
-
DEBUG_INJECTION_FUNCTIONS = new WeakMap();
|
|
1865
|
-
}
|
|
1866
|
-
|
|
1867
|
-
/**
|
|
1868
|
-
@module ember
|
|
1869
|
-
@private
|
|
1870
|
-
*/
|
|
1871
|
-
|
|
1872
|
-
/**
|
|
1873
|
-
Read-only property that returns the result of a container lookup.
|
|
1874
|
-
|
|
1875
|
-
@class InjectedProperty
|
|
1876
|
-
@namespace Ember
|
|
1877
|
-
@constructor
|
|
1878
|
-
@param {String} type The container type the property will lookup
|
|
1879
|
-
@param {String} nameOrDesc (optional) The name the property will lookup, defaults
|
|
1880
|
-
to the property's name
|
|
1881
|
-
@private
|
|
1882
|
-
*/
|
|
1883
|
-
// Decorator factory (with args)
|
|
1884
|
-
// (Also matches non-decorator form, types may be incorrect for this.)
|
|
1885
|
-
|
|
1886
|
-
// Non-decorator
|
|
1887
|
-
|
|
1888
|
-
// Decorator (without args)
|
|
1889
|
-
|
|
1890
|
-
// Catch-all for service and controller injections
|
|
1891
|
-
|
|
1892
|
-
function inject(type, ...args) {
|
|
1893
|
-
(!(typeof type === 'string') && assert('a string type must be provided to inject', typeof type === 'string'));
|
|
1894
|
-
let elementDescriptor;
|
|
1895
|
-
let name;
|
|
1896
|
-
if (isElementDescriptor(args)) {
|
|
1897
|
-
elementDescriptor = args;
|
|
1898
|
-
} else if (typeof args[0] === 'string') {
|
|
1899
|
-
name = args[0];
|
|
1900
|
-
}
|
|
1901
|
-
let getInjection = function (propertyName) {
|
|
1902
|
-
let owner = getOwner(this) || this.container; // fallback to `container` for backwards compat
|
|
1903
|
-
(!(Boolean(owner)) && assert(`Attempting to lookup an injected property on an object without a container, ensure that the object was instantiated via a container.`, Boolean(owner)));
|
|
1904
|
-
return owner.lookup(`${type}:${name || propertyName}`);
|
|
1905
|
-
};
|
|
1906
|
-
{
|
|
1907
|
-
DEBUG_INJECTION_FUNCTIONS.set(getInjection, {
|
|
1908
|
-
type,
|
|
1909
|
-
name
|
|
1910
|
-
});
|
|
1911
|
-
}
|
|
1912
|
-
let decorator = computed({
|
|
1913
|
-
get: getInjection,
|
|
1914
|
-
set(keyName, value) {
|
|
1915
|
-
defineProperty(this, keyName, null, value);
|
|
1916
|
-
}
|
|
1917
|
-
});
|
|
1918
|
-
if (elementDescriptor) {
|
|
1919
|
-
return decorator(elementDescriptor[0], elementDescriptor[1], elementDescriptor[2]);
|
|
1920
|
-
} else {
|
|
1921
|
-
return decorator;
|
|
1922
|
-
}
|
|
1923
|
-
}
|
|
1924
|
-
|
|
1925
|
-
/**
|
|
1926
|
-
@decorator
|
|
1927
|
-
@private
|
|
1928
|
-
|
|
1929
|
-
Marks a property as tracked.
|
|
1930
|
-
|
|
1931
|
-
By default, a component's properties are expected to be static,
|
|
1932
|
-
meaning you are not able to update them and have the template update accordingly.
|
|
1933
|
-
Marking a property as tracked means that when that property changes,
|
|
1934
|
-
a rerender of the component is scheduled so the template is kept up to date.
|
|
1935
|
-
|
|
1936
|
-
There are two usages for the `@tracked` decorator, shown below.
|
|
1937
|
-
|
|
1938
|
-
@example No dependencies
|
|
1939
|
-
|
|
1940
|
-
If you don't pass an argument to `@tracked`, only changes to that property
|
|
1941
|
-
will be tracked:
|
|
1942
|
-
|
|
1943
|
-
```typescript
|
|
1944
|
-
import Component from '@glimmer/component';
|
|
1945
|
-
import { tracked } from '@glimmer/tracking';
|
|
1946
|
-
|
|
1947
|
-
export default class MyComponent extends Component {
|
|
1948
|
-
@tracked
|
|
1949
|
-
remainingApples = 10
|
|
1950
|
-
}
|
|
1951
|
-
```
|
|
1952
|
-
|
|
1953
|
-
When something changes the component's `remainingApples` property, the rerender
|
|
1954
|
-
will be scheduled.
|
|
1955
|
-
|
|
1956
|
-
@example Dependents
|
|
1957
|
-
|
|
1958
|
-
In the case that you have a computed property that depends other
|
|
1959
|
-
properties, you want to track both so that when one of the
|
|
1960
|
-
dependents change, a rerender is scheduled.
|
|
1961
|
-
|
|
1962
|
-
In the following example we have two properties,
|
|
1963
|
-
`eatenApples`, and `remainingApples`.
|
|
1964
|
-
|
|
1965
|
-
```typescript
|
|
1966
|
-
import Component from '@glimmer/component';
|
|
1967
|
-
import { tracked } from '@glimmer/tracking';
|
|
1968
|
-
|
|
1969
|
-
const totalApples = 100;
|
|
1970
|
-
|
|
1971
|
-
export default class MyComponent extends Component {
|
|
1972
|
-
@tracked
|
|
1973
|
-
eatenApples = 0
|
|
1974
|
-
|
|
1975
|
-
get remainingApples() {
|
|
1976
|
-
return totalApples - this.eatenApples;
|
|
1977
|
-
}
|
|
1978
|
-
|
|
1979
|
-
increment() {
|
|
1980
|
-
this.eatenApples = this.eatenApples + 1;
|
|
1981
|
-
}
|
|
1982
|
-
}
|
|
1983
|
-
```
|
|
1984
|
-
|
|
1985
|
-
@param dependencies Optional dependents to be tracked.
|
|
1986
|
-
*/
|
|
1987
|
-
|
|
1988
|
-
function tracked(...args) {
|
|
1989
|
-
(!(!(isElementDescriptor(args.slice(0, 3)) && args.length === 5 && args[4] === true)) && assert(`@tracked can only be used directly as a native decorator. If you're using tracked in classic classes, add parenthesis to call it like a function: tracked()`, !(isElementDescriptor(args.slice(0, 3)) && args.length === 5 && args[4] === true)));
|
|
1990
|
-
if (!isElementDescriptor(args)) {
|
|
1991
|
-
let propertyDesc = args[0];
|
|
1992
|
-
(!(args.length === 0 || typeof propertyDesc === 'object' && propertyDesc !== null) && assert(`tracked() may only receive an options object containing 'value' or 'initializer', received ${propertyDesc}`, args.length === 0 || typeof propertyDesc === 'object' && propertyDesc !== null));
|
|
1993
|
-
if (propertyDesc) {
|
|
1994
|
-
let keys = Object.keys(propertyDesc);
|
|
1995
|
-
(!(keys.length <= 1 && (keys[0] === undefined || keys[0] === 'value' || keys[0] === 'initializer')) && assert(`The options object passed to tracked() may only contain a 'value' or 'initializer' property, not both. Received: [${keys}]`, keys.length <= 1 && (keys[0] === undefined || keys[0] === 'value' || keys[0] === 'initializer')));
|
|
1996
|
-
(!(!('initializer' in propertyDesc) || typeof propertyDesc.initializer === 'function') && assert(`The initializer passed to tracked must be a function. Received ${propertyDesc.initializer}`, !('initializer' in propertyDesc) || typeof propertyDesc.initializer === 'function'));
|
|
1997
|
-
}
|
|
1998
|
-
let initializer = propertyDesc ? propertyDesc.initializer : undefined;
|
|
1999
|
-
let value = propertyDesc ? propertyDesc.value : undefined;
|
|
2000
|
-
let decorator = function (target, key, _desc, _meta, isClassicDecorator) {
|
|
2001
|
-
(!(isClassicDecorator) && assert(`You attempted to set a default value for ${key} with the @tracked({ value: 'default' }) syntax. You can only use this syntax with classic classes. For native classes, you can use class initializers: @tracked field = 'default';`, isClassicDecorator));
|
|
2002
|
-
let fieldDesc = {
|
|
2003
|
-
initializer: initializer || (() => value)
|
|
2004
|
-
};
|
|
2005
|
-
return descriptorForField([target, key, fieldDesc]);
|
|
2006
|
-
};
|
|
2007
|
-
setClassicDecorator(decorator);
|
|
2008
|
-
return decorator;
|
|
2009
|
-
}
|
|
2010
|
-
return descriptorForField(args);
|
|
2011
|
-
}
|
|
2012
|
-
{
|
|
2013
|
-
// Normally this isn't a classic decorator, but we want to throw a helpful
|
|
2014
|
-
// error in development so we need it to treat it like one
|
|
2015
|
-
setClassicDecorator(tracked);
|
|
2016
|
-
}
|
|
2017
|
-
function descriptorForField([target, key, desc]) {
|
|
2018
|
-
(!(!desc || !desc.value && !desc.get && !desc.set) && assert(`You attempted to use @tracked on ${key}, but that element is not a class field. @tracked is only usable on class fields. Native getters and setters will autotrack add any tracked fields they encounter, so there is no need mark getters and setters with @tracked.`, !desc || !desc.value && !desc.get && !desc.set));
|
|
2019
|
-
let {
|
|
2020
|
-
getter,
|
|
2021
|
-
setter
|
|
2022
|
-
} = trackedData(key, desc ? desc.initializer : undefined);
|
|
2023
|
-
function get() {
|
|
2024
|
-
let value = getter(this);
|
|
2025
|
-
|
|
2026
|
-
// Add the tag of the returned value if it is an array, since arrays
|
|
2027
|
-
// should always cause updates if they are consumed and then changed
|
|
2028
|
-
if (Array.isArray(value) || isEmberArray(value)) {
|
|
2029
|
-
consumeTag(tagFor(value, '[]'));
|
|
2030
|
-
}
|
|
2031
|
-
return value;
|
|
2032
|
-
}
|
|
2033
|
-
function set(newValue) {
|
|
2034
|
-
setter(this, newValue);
|
|
2035
|
-
dirtyTagFor(this, SELF_TAG);
|
|
2036
|
-
}
|
|
2037
|
-
let newDesc = {
|
|
2038
|
-
enumerable: true,
|
|
2039
|
-
configurable: true,
|
|
2040
|
-
isTracked: true,
|
|
2041
|
-
get,
|
|
2042
|
-
set
|
|
2043
|
-
};
|
|
2044
|
-
COMPUTED_SETTERS.add(set);
|
|
2045
|
-
meta(target).writeDescriptors(key, new TrackedDescriptor(get, set));
|
|
2046
|
-
return newDesc;
|
|
2047
|
-
}
|
|
2048
|
-
class TrackedDescriptor {
|
|
2049
|
-
constructor(_get, _set) {
|
|
2050
|
-
this._get = _get;
|
|
2051
|
-
this._set = _set;
|
|
2052
|
-
CHAIN_PASS_THROUGH.add(this);
|
|
2053
|
-
}
|
|
2054
|
-
get(obj) {
|
|
2055
|
-
return this._get.call(obj);
|
|
2056
|
-
}
|
|
2057
|
-
set(obj, _key, value) {
|
|
2058
|
-
this._set.call(obj, value);
|
|
2059
|
-
}
|
|
2060
|
-
}
|
|
2061
|
-
|
|
2062
|
-
export { tracked as $, revalidateObservers as A, descriptorForDecorator as B, ComputedProperty as C, DEBUG_INJECTION_FUNCTIONS as D, addListener as E, removeListener as F, makeComputedDecorator as G, flushAsyncObservers as H, ComputedDescriptor as I, CHAIN_PASS_THROUGH as J, getChainTagsForKey as K, finishLazyChains as L, on as M, LIBRARIES as N, PROPERTY_DID_CHANGE as O, PROXY_CONTENT as P, objectAt as Q, autoComputed as R, changeProperties as S, ASYNC_OBSERVERS as T, Libraries as U, SYNC_OBSERVERS as V, TrackedDescriptor as W, _getProp as X, isComputed as Y, markObjectAsDirty as Z, _getPath as _, tagForProperty as a, descriptorForProperty as b, computed as c, defineProperty as d, expandProperties as e, isClassicDecorator as f, get as g, hasUnknownProperty as h, isElementDescriptor as i, activateObserver as j, sendEvent as k, inject as l, isPath as m, notifyPropertyChange as n, COMPUTED_SETTERS as o, getPossibleMandatoryProxyValue as p, hasListeners as q, removeObserver as r, setClassicDecorator as s, tagForObject as t, addObserver as u, endPropertyChanges as v, beginPropertyChanges as w, nativeDescDecorator as x, defineValue as y, defineDecorator as z };
|