Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

built-in cached decorator causes "decorator is not a function" error. #1086

Closed
NullVoxPopuli opened this issue Jan 23, 2022 · 6 comments
Closed

Comments

@NullVoxPopuli
Copy link
Collaborator

NullVoxPopuli commented Jan 23, 2022

my component (in browser)
let Game = (0,_externals_ember_component__WEBPACK_IMPORTED_MODULE_2__.setComponentTemplate)((0,_externals_ember_template_factory__WEBPACK_IMPORTED_MODULE_1__.createTemplateFactory)(
/*
  
    {{this.todaysWord}}



  
*/
{
  "id": "mu2ajeIA",
  "block": "[[[1,\"\\n    \"],[1,[30,0,[\"todaysWord\"]]],[1,\"\\n\\n\\n\\n  \"]],[],false,[]]",
  "moduleName": "wordle/components/game.ts",
  "isStrictMode": true
}), (_class = class Game extends _glimmer_component__WEBPACK_IMPORTED_MODULE_3__["default"] {
  // wordList = trackedFunction(this, async () => {
  //   return await import(/* webpackIgnore */ '/words.js');
  // });
  get todaysWord() {
    let {
      answers
    } = this.wordList.value;
    let index = toDate(this.args.day).getTime() % answers.length;
    return answers[index];
  }

  get state() {
    return initialStateFor(this.args.day);
  }

}, ((0,_home_lprestonsegoiii_Development_NullVoxPopuli_wordle_node_modules_babel_runtime_helpers_esm_applyDecoratedDescriptor_js__WEBPACK_IMPORTED_MODULE_0__["default"])(_class.prototype, "todaysWord", [_glimmer_tracking__WEBPACK_IMPORTED_MODULE_4__.cached], Object.getOwnPropertyDescriptor(_class.prototype, "todaysWord"), _class.prototype), (0,_home_lprestonsegoiii_Development_NullVoxPopuli_wordle_node_modules_babel_runtime_helpers_esm_applyDecoratedDescriptor_js__WEBPACK_IMPORTED_MODULE_0__["default"])(_class.prototype, "state", [_glimmer_tracking__WEBPACK_IMPORTED_MODULE_4__.cached], Object.getOwnPropertyDescriptor(_class.prototype, "state"), _class.prototype)), _class));
source
import Component from '@glimmer/component';
import { service } from '@ember/service';
import { cached } from '@glimmer/tracking';
import { tracked } from 'ember-deep-tracked';
// import { trackedFunction } from 'ember-resources';

interface Args {
  // year-month-day
  day: string;
}

export default class Game extends Component<Args> {
  // wordList = trackedFunction(this, async () => {
  //   return await import(/* webpackIgnore */ '/words.js');
  // });

  @cached
  get todaysWord() {
    let { answers }  = this.wordList.value;
    let index = toDate(this.args.day).getTime() % answers.length;

    return answers[index];
  }

  @cached
  get state() {
    return initialStateFor(this.args.day);
  }


  <template>
    {{this.todaysWord}}

  </template>
}

function initialStateFor(day) {
  return {};
}

function toDate(dayString: string) {
  let [year, month, day] = dayString.split('-');
  let date = new Date(year, month, day);

  return date;
}

cached was introduced to ember natively here:

and released in:

my app's version of ember:

  • 4.3.0-alpha.2

This might be related to:

@NullVoxPopuli
Copy link
Collaborator Author

this errors happens on 4.1.0 as well

image

@ef4
Copy link
Contributor

ef4 commented Jan 24, 2022

@glimmer/tracking is 100% shenanigans, the implementation inside the package itself doesn't even work in ember. So we're forced to completely replace it with a compat adapter:

`export { createCache, getValue, isConst } from "@ember/-internals/metal";`

If you add cached to that line it should fix the problem.

@mkszepp
Copy link
Contributor

mkszepp commented Feb 18, 2022

@ef4 @NullVoxPopuli i have tested the @cached decorator with embroider v1.2.0 and it doesn't work

grafik
grafik

grafik

Ember: 4.1.0
Embroider: 1.2.0
OS: Win 10

Steps to reproduce:

  1. Create a new ember app with embroider ember new test-app ---embroider=true
  2. ember g controller application
  3. Add the following code in project
import Controller from '@ember/controller';
import { cached } from '@glimmer/tracking';

export default class ApplicationController extends Controller {
    @cached
    get title() {
        return 'Cached test';
    }
}

@trabus
Copy link

trabus commented Mar 1, 2022

Also hitting this on a brand new ember-cli v4.1.1 app with 1.2.0

├── @ember/[email protected]
├── @ember/[email protected]
├── @embroider/[email protected]
├── @embroider/[email protected]
├── @embroider/[email protected]
├── @glimmer/[email protected]
├── @glimmer/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
export 'cached' (imported as 'cached') was not found in '@glimmer/tracking' (possible exports: tracked)

I tried two ways, one by using ember new my-app --embroider and then generating a new app and adding embroider manually, and I hit the import error both ways.

@mkszepp
Copy link
Contributor

mkszepp commented Mar 1, 2022

@trabus the bug should be fixed with this changes: #1135.

The fix is already in main branch and we need to wait for a release

As work around, you can use the ember-cached-decorator-polyfill, but it works only with embroider <= 1.0.0, because in 1.1 it was added the @cached on the wrong spot

@mkszepp
Copy link
Contributor

mkszepp commented Mar 7, 2022

@trabus fix is now released in embroider v1.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants