Ember Octane vs Marko Comparison
Reactivity
Declare state
Ember Octane
name.hbs
<h1>Hello {{this.name}}</h1>
name.js
Marko
Name.marko
<let/name = "John"/>
<h1>Hello ${name}</h1>
Update state
Ember Octane
name.hbs
<h1>Hello {{this.name}}</h1>
name.js
Marko
Name.marko
<let/name = "John"/>
<effect() { name = "Jane" }/>
<h1>Hello ${name}</h1>
Computed state
Ember Octane
double-count.hbs
<div>{{this.doubleCount}}</div>
double-count.js
Marko
DoubleCount.marko
<let/count = 10/>
<const/doubleCount = count * 2/>
<div>${doubleCount}</div>
Templating
Minimal template
Ember Octane
hello-world.hbs
<h1>Hello world</h1>
Marko
HelloWorld.marko
<h1>Hello world</h1>
Styling
Ember Octane
css-style.css
/* using: https://github.com/salsify/ember-css-modules */
.title {
color: red;
}
css-style.hbs
Marko
CssStyle.marko
<h1.title>I am red</h1>
<button style={ fontSize: "10rem" }>I am a button</button>
<button class=scopedButton>I am a style-scoped button</button>
<style>
.title {
color: red;
}
</style>
<style/{ scopedButton }>
.scopedButton {
font-size: 10rem;
}
</style>
Loop
Ember Octane
colors.hbs
<ul>
{{#each (array "red" "green" "blue") as |color|}}
<li>{{color}}</li>
{{/each}}
</ul>
Marko
Colors.marko
<ul>
<for|color| of=["red", "green", "blue"]>
<li>${color}</li>
</for>
</ul>
Event click
Ember Octane
counter.hbs
<p>Counter: {{this.count}}</p>
<button {{on "click" this.incrementCount}}>+1</button>
counter.js
Marko
Counter.marko
<let/count = 0/>
<p>Counter: ${count}</p>
<button onClick() { count++ }>+1</button>
Dom ref
Ember Octane
input-focused.hbs
<input {{this.autofocus}} />
input-focused.js
Marko
InputFocused.marko
<input/inputElement>
<effect() { inputElement().focus() }/>
Conditional
Ember Octane
traffic-light.hbs
<button {{on "click" this.nextLight}}>Next light</button>
<p>Light is: {{this.light}}</p>
<p>
You must
{{#if (eq this.light "red")}}
STOP
{{else if (eq this.light "orange")}}
SLOW DOWN
{{else if (eq this.light "green")}}
GO
{{/if}}
</p>
traffic-light.js
Marko
TrafficLight.marko
static const TRAFFIC_LIGHTS = ["red", "orange", "green"];
<let/lightIndex = 0/>
<const/light = TRAFFIC_LIGHTS[lightIndex]/>
<button onClick() { lightIndex = (lightIndex + 1) % TRAFFIC_LIGHTS.length }>
Next light
</button>
<p>Light is: ${light}</p>
<p>
You must
<if=light === "red">STOP</if>
<else-if=light === "orange">SLOW DOWN</else-if>
<else>GO</else>
</p>
Lifecycle
On mount
Ember Octane
page-title.hbs
<p>Page title is: {{(this.pageTitle)}}</p>
page-title.js
Marko
PageTitle.marko
<let/pageTitle = ""/>
<effect() { pageTitle = document.title }/>
<p>Page title: ${pageTitle}</p>
On unmount
Ember Octane
time.hbs
<p>Current time: {{this.time}}</p>
time.js
Marko
Time.marko
<let/time = new Date()/>
<lifecycle
onMount() { this.timer = setInterval(_ => time = new Date(), 1000) }
onDestroy() { clearInterval(this.timer) }
/>
<p>Current time: ${time.toLocaleTimeString()}</p>
Component composition
Props
Ember Octane
app.hbs
<UserProfile
@name="John"
@age={{20}}
@favouriteColors={{array "green" "blue" "red"}}
@isAvailable={{true}}
/>
user-profile.hbs
user-profile.js
Marko
App.marko
<UserProfile
name="John"
age=20
favouriteColors=["green", "blue", "red"]
isAvailable
/>
Emit to parent
Ember Octane
app.hbs
<p>Are you happy?</p>
<AnswerButton @onYes={{this.handleYes}} @onNo={{this.handleNo}} />
<p style="font-size: 50px;">{{if this.isHappy "😀" "😥"}}</p>
app.js
answer-button.hbs
Marko
App.marko
<let/isHappy = true/>
<p>Are you happy?</p>
<AnswerButton
onYes() { isHappy = true }
onNo() { isHappy = false }
/>
<p style={ fontSize: 50 }>${isHappy ? "😀" : "😥"}</p>
Slot
Ember Octane
app.hbs
<FunnyButton> Click me! </FunnyButton>
funny-button.hbs
Marko
App.marko
<FunnyButton>Click me!</FunnyButton>
Slot fallback
Ember Octane
app.hbs
<FunnyButton />
<FunnyButton>I got content!</FunnyButton>
funny-button.hbs
Marko
App.marko
<FunnyButton/>
<FunnyButton>I got content!</FunnyButton>
Context
Ember Octane
app.hbs
<UserProfile />
user-profile.hbs
user-profile.js
user-service.js
Marko
App.marko
<let/user = {
id: 1,
username: "unicorn42",
email: "unicorn42@example.com",
}/>
<const/updateUsername(newUsername) {
user = { ...user, username: newUsername };
}/>
<h1>Welcome back, ${user.username}</h1>
<set={ ...user, updateUsername }>
<UserProfile />
</set>
Form input
Input text
Ember Octane
input-hello.hbs
<p>{{this.text}}</p>
<input value={{this.text}} {{on "input" this.handleInput}} />
input-hello.js
Marko
InputHello.marko
<let/text = "Hello world"/>
<p>${text}</p>
<input value:=text/>
Checkbox
Ember Octane
is-available.hbs
<input
id="is-available"
type="checkbox"
checked={{this.isAvailable}}
{{on "change" this.handleChange}}
/>
<label for="is-available">Is available</label>
is-available.js
Marko
IsAvailable.marko
<input#is-available
type="checkbox"
checked:=input.isAvailable
/>
<label for="is-available">Is available</label>
Radio
Ember Octane
pick-pill.hbs
<div>Picked: {{this.picked}}</div>
<input
id="blue-pill"
type="radio"
value="blue"
checked={{eq this.picked "blue"}}
{{on "change" this.handleChange}}
/>
<label htmlFor="blue-pill">Blue pill</label>
<input
id="red-pill"
type="radio"
value="red"
checked={{eq this.picked "red"}}
{{on "change" this.handleChange}}
/>
<label htmlFor="red-pill">Red pill</label>
pick-pill.js
Marko
PickPill.marko
<let/picked = "red"/>
<const/handleChange(event) {
picked = event.target.value;
}/>
<div>Picked: ${picked}</div>
<input#blue-pill
type="radio"
checked=picked === "blue"
value="blue"
onChange=handleChange
/>
<label for="blue-pill">Blue pill</label>
<input#red-pill
type="radio"
checked=picked === "red"
value="red"
onChange=handleChange
/>
<label for="red-pill">Red pill</label>
Select
Ember Octane
color-select.hbs
<select {{on "change" this.select}}>
{{#each this.colors as |color|}}
<option
value={{color.id}}
disabled={{color.isDisabled}}
selected={{eq color.id this.selectedColorId}}
>
{{color.text}}
</option>
{{/each}}
</select>
color-select.js
Marko
ColorSelect.marko
static const colors = [
{ id: 1, text: "red" },
{ id: 2, text: "blue" },
{ id: 3, text: "green" },
{ id: 4, text: "gray", isDisabled: true },
];
<let/selectedColorId = 2/>
<select onChange(event) { selectedColorId = event.target.value }>
<for|{ id, isDisabled, text }| of=colors>
<option value=id disabled=isDisabled selected=id === selectedColorId>
${text}
</option>
</for>
</select>
Webapp features
Render app
Ember Octane
Missing snippet
Marko
index.marko
<!DOCTYPE html>
<html>
<App/>
</html>
App.marko
Fetch data
Ember Octane
app.hbs
{{#let (this.fetchUsers) as |request|}}
{{#if request.isLoading}}
<p>Fetching users...</p>
{{else if request.error}}
<p>An error occurred while fetching users</p>
{{else}}
<ul>
{{#each request.users as |user|}}
<li>
<img src={{user.picture.thumbnail}} alt="user" />
<p>{{user.name.first}} {{user.name.last}}</p>
</li>
{{/each}}
</ul>
{{/if}}
{{/let}}
app.js
Marko
App.marko
<await(fetch("https://randomuser.me/api/?results=3").then(res => res.json()))>
<@placeholder>
<p>Fetching users...</p>
</@placeholder>
<@catch|error|>
<p>An error occurred while fetching users</p>
</@catch>
<@then|{ results: users }|>
<ul>
<for|{ picture, name }| of=users>
<li>
<img src=picture.thumbnail alt="user">
<p>${name.first} ${name.last}</p>
</li>
</for>
</ul>
</@then>
</await>
Decouvrez plus d’Offres de la plateform ItGalaxy.io :
Découvrez notre gamme complète de services et formations pour accélérer votre carrière.
1. Nous contactez
- Description: Besoin de Formation et des Solutions cloud complètes pour vos applications
- Links:
2. Infra as a Service
- Description: Infrastructure cloud évolutive et sécurisée
- Links:
3. Projets Développeurs
- Description: Découvrez des opportunités passionnantes pour les développeurs
- Links:
4. Développeurs
- Description: Rejoignez notre communauté de développeurs
- Links:
5. Formations Complètes
- Description: Accédez à des formations professionnelles de haute qualité
- Links:
6. Marketplace
- Description: Découvrez notre place de marché de services
- Links:
7. Blogs
- Description: Découvrez nos blogs
- Links:
- comment creer une application mobile ?
- Comment monitorer un site web ?
- Command Checkout in git ?
- Comment git checkout to commit ?
- supprimer une branche git
- dockercoin
- kubernetes c est quoi
- architecture kubernetes
- Installer Gitlab Runner ?
- .gitlab-ci.yml exemples
- CI/CD
- svelte 5 vs solid
- svelte vs lit
- solidjs vs qwik
- alpine vs vue
- Plateform Freelance 2025
- Creation d’un site Web gratuitement
This website is powered by ItGalaxy.io