NullVoxPopuli / ember-cheat-sheet

A cheat sheet for converting between classic and octane edition of Ember
https://cheatsheet.glimmer.nullvoxpopuli.com/docs
MIT License
14 stars 10 forks source link

Epic - cheat sheet content we should/could draft #50

Open jenweber opened 3 years ago

jenweber commented 3 years ago

As much as possible, I would like to reuse code examples from the Octane cheatsheet, and then add more for template syntax. The 🆕 indicates things that do not have an example in the old cheatsheet. Please comment on anything you think is missing, what should be removed, and which of the 🆕 things are highest priority.

Ember Data also needs a cheat sheet, but I think it should be separate.

Using components in templates

Fetching data

Passing and mutating data

Interaction

General Template syntax & helpers

Routes

Component class

Notes from Twitter

Possible way to describe the template syntax:

Expression =
  | SubExpression
  | Value

SubExpression =
  | (Helper, ...Value[])

Value = 
  | number
  | string
  | boolean
  | undefined
  | null
  | SubExpression 
jenweber commented 3 years ago

@NullVoxPopuli let me know your thoughts! Also if you can add me to this repo as a member, that would be helpful. I can make a feature branch that drafts this content as plain markdown and tag you for review whenever I have something new.

yratanov commented 3 years ago

@jenweber Good plan!

Example of passing an attr to the component with one-way change. like @tracked internalState = this.args.externalState, which will update if @externalState is being changed, but not vice versa. The only way I see doing it is {{did-update @externalState this.changeInternalState}}.

NullVoxPopuli commented 3 years ago

I'm generally in favor,

Some additional thoughts:

NullVoxPopuli commented 3 years ago

like @tracked internalState = this.args.externalState, which will update if @externalState is being changed,

if you happen to need this now, you'd do it like:

yarn add tracked-toolbax
@localCopy('args.text') myText; // can be set, re-sets to args.text when args.text changes

see: https://github.com/pzuraq/tracked-toolbox

if you wanted to do this vanilla, you can use the same approach as you would with class instance values:

import { cached } from '@glimmer/tracking';
import { getOwner, setOwner } from '@ember/application';

// ...

@cached
get myValue() {
  let instance = new MyClass(this.args.externalState);
  setOwner(instance, getOwner(this));
  return instance;
}

then myValue only creates a new MyClass when externalState changes. Note that set/get owner not needed, but most folks like using services and stuff from their custom classes, and set/get owner enables that.

NullVoxPopuli commented 2 years ago

additional topics -- everything from here?: https://discuss.emberjs.com/t/collection-of-strict-mode-template-demos-of-various-concepts/19637 (as well as the provided demos on limber.glimdown.com (focus management, forms, etc etc)

and maybe also a collection of anti-patterns so that it's clear where the ecosystem stands?

by use-case alternatives, because effects are rare to reach for (or should be (even in React))