Skip to content

Commit be0597d

Browse files
committed
Oh, can I actually delete these hacks?
1 parent e560d22 commit be0597d

File tree

3 files changed

+1
-66
lines changed

3 files changed

+1
-66
lines changed

ember-resources/src/resource.ts

-2
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,4 @@ export function resource<Value>(
202202
let configured = new Builder(setup, CREATE_KEY);
203203

204204
return configured;
205-
206-
return wrapForPlainUsage(context, configured);
207205
}

ember-resources/src/utils.ts

-63
Original file line numberDiff line numberDiff line change
@@ -35,66 +35,3 @@ export function getCurrentValue<Value>(value: Value | Reactive<Value>): Value {
3535

3636
return value;
3737
}
38-
39-
/**
40-
* This is what allows resource to be used without @use.
41-
* The caveat though is that a property must be accessed
42-
* on the return object.
43-
*
44-
* A resource not using use *must* be an object.
45-
*/
46-
export function wrapForPlainUsage<Value>(context: object, builder: Builder<Value>) {
47-
let cache: Resource<Value>;
48-
49-
/*
50-
* Having an object that we use invokeHelper + getValue on
51-
* is how we convert the "function" in to a reactive utility
52-
* (along with the following proxy for accessing anything on this 'value')
53-
*
54-
*/
55-
const target = {
56-
get [INTERMEDIATE_VALUE]() {
57-
if (!cache) {
58-
cache = builder.create();
59-
cache.link(context);
60-
}
61-
62-
// SAFETY: the types for the helper manager APIs aren't fully defined to infer
63-
// nor allow passing the value.
64-
return cache.current;
65-
},
66-
};
67-
68-
/**
69-
* This proxy takes everything called on or accessed on "target"
70-
* and forwards it along to target[INTERMEDIATE_VALUE] (where the actual resource instance is)
71-
*
72-
* It's important to only access .[INTERMEDIATE_VALUE] within these proxy-handler methods so that
73-
* consumers "reactively entangle with" the Resource.
74-
*/
75-
return new Proxy(target, {
76-
get(target, key): unknown {
77-
const state = target[INTERMEDIATE_VALUE];
78-
79-
assert('[BUG]: it should not have been possible for this to be undefined', state);
80-
81-
return Reflect.get(state, key, state);
82-
},
83-
84-
ownKeys(target): (string | symbol)[] {
85-
const value = target[INTERMEDIATE_VALUE];
86-
87-
assert('[BUG]: it should not have been possible for this to be undefined', value);
88-
89-
return Reflect.ownKeys(value);
90-
},
91-
92-
getOwnPropertyDescriptor(target, key): PropertyDescriptor | undefined {
93-
const value = target[INTERMEDIATE_VALUE];
94-
95-
assert('[BUG]: it should not have been possible for this to be undefined', value);
96-
97-
return Reflect.getOwnPropertyDescriptor(value, key);
98-
},
99-
}) as never as Value;
100-
}

test-app/tests/core/raw-api-test.gts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { click, render } from '@ember/test-helpers';
55
import { module, test } from 'qunit';
66
import { setupRenderingTest, setupTest } from 'ember-qunit';
77

8-
import { cell, resource, resourceFactory } from 'ember-resources';
8+
import { resource } from 'ember-resources';
99

1010
module('RAW', function (hooks) {
1111
setupTest(hooks);

0 commit comments

Comments
 (0)