Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Sadhan Sarker
Sadhan Sarker

Posted on • Edited on

     

Ember Octane Preview Highlights

Alt Text

😎It's time for Ember Octane! Sound great!

Official Announcement

Octane becomes the default for Ember, Thanks in advance! If you are looking for the latest stable release of Ember, please instead visit guides.emberjs.com.

Quick roll-up withember octant You can find the details guide from theofficial site.

  1. install Node.js
  2. then open terminal then hit
npm install -g ember-cliember new ember-quickstart -b @ember/octane-app-blueprint
Enter fullscreen modeExit fullscreen mode

👌 Congratulations!. We make it, see how easy it was?.

Note:- I'm not going to focus on each section as we know ember official guide is super useful and more advance. Here, I'm going to cover something those are really essential when we roll up with a project.

Ohm! One thing I forgot to talk about

EmberJs related update news we can findhere!

😨 Okay it's too much talk now let's begin


1. Play with the octane new component features.

We can create a component using CLI from the terminal,

ember g component person
Enter fullscreen modeExit fullscreen mode

Open,app/components/person.js and includes

importComponentfrom'@glimmer/component';import{tracked}from'@glimmer/tracking';import{action,get,set}from'@ember/object';import{injectasservice}from'@ember/service';exportdefaultclassPersonComponentextendsComponent{name="Hello from - Person Component";@trackedbindableVariable='It makes two way binding easier';@servicestore;// access ember data easily.@servicerouter;// access router from componentperson={};// declare object// array declarationpersons=[{name:"ABC",country:"Bangladesh"},{name:"DEF",country:"Dhaka"},]// replacement of init() methodconstructor(){super(...arguments);this.bindableVariable="change it nolonger needs set() method";set(this.person,'name','Sadhan');set(this.persons[1],'name','Sadhan');console.log('person',this.person);console.log('persons',this.persons);}@actiononClick(){alert('Great Job! We can make it!')// dynamically we can navigate to different route from componentthis.router.transitionTo('About');// make sure you have this route}}
Enter fullscreen modeExit fullscreen mode

Now open,app/components/person.hbs add includes

<h1>{{this.name}}</h1><!-- open up, your browser dev console -->{{logthis.person}}<p>Updated Value is:{{this.bindableVariable}}<p><ol>{{#eachthis.personsas|item|}}<li>{{item.name}}</li>{{/each}}</ol><button{{on"click"this.onClick}}>Clik Me!</button>
Enter fullscreen modeExit fullscreen mode

Initially, we make it.

2. Handling From Elements

ember g component state
Enter fullscreen modeExit fullscreen mode

Open,app/components/state.js and includes

importComponentfrom'@glimmer/component';import{tracked}from'@glimmer/tracking';import{action,get,set}from'@ember/object';import{injectasservice}from'@ember/service';importutilsfrom"../utils";exportdefaultclassStateComponentextendsComponent{@trackedstateData={label:'',description:'',code:''};@trackedisPermitToSave=false;constructor(){super(...arguments);}@actiononChange(event){letcode=event.target.value.trim();if(code){if(code){set(this.stateData,'code',code);}}this.isPermitToSave=true;}@actionsave(){console.log('Save Data:-',this.stateData);// after save, optional staff we can dothis.isPermitToSave=false;this.stateData={};}}
Enter fullscreen modeExit fullscreen mode

Now open,app/components/state.hbs and includes

<h1>Hello from, Form Manipulation</h1><labelfor="select">Select Class:</label><selectid="select"onchange={{actionthis.onChange}}><optionvalue="">-- Select One --</option><optionvalue="item1">items 1</option><optionvalue="item2">items 2</option></select><labelfor="label">Label:</label><inputvalue={{this.stateData.label}}onchange={{action(mutthis.stateData.label)value="target.value"}}type="text"placeholder="Ex. ABC"><labelfor="description">Description:</label><inputvalue={{this.stateData.description}}onchange={{action(mutthis.stateData.description)value="target.value"}}type="text"id="description"placeholder="Ex. ABC Description">{{#ifthis.isPermitToSave}}<button{{on'click'this.save}}>Save</button>{{/if}}
Enter fullscreen modeExit fullscreen mode

Note: Here, I'm just trying to cover basic form binding but the recommendation will be using theember servicefeature. I will try to cover its future if I can.

😎Great! another achievement.


3. Dynamic Component Injection with passing data & function reference

ember g controller applicationember g component dci
Enter fullscreen modeExit fullscreen mode

open,app/controllers/application.js and includes

importControllerfrom'@ember/controller';import{action,get,set}from'@ember/object';import{tracked}from"@glimmer/tracking";exportdefaultclassApplicationControllerextendsController{@trackedcomponentName='dci';@actionparentFunc(value){alert('Hello From Parent:-'+value);}}
Enter fullscreen modeExit fullscreen mode

Openapp/templates/application.hbs

{{#componentgreetingMSG='Hello From, DCI Component'functionRef=this.parentFunc}}<h1> Welcome Here!</h1>{{/component}}
Enter fullscreen modeExit fullscreen mode

Open,app/components/dci.js and includes

importComponentfrom'@glimmer/component';exportdefaultclassDciComponentextendsComponent{constructor(){super(...arguments);console.log('Parent data:-',this.args.greetingMSG;this.args.functionRef('ABC');// it will call parent function}}
Enter fullscreen modeExit fullscreen mode

Now open,app/components/dci.js and includes another implementation

<h1>{{this.args.greetingMSG}}</h1><button{{on'click'this.functionRef'ABC'}}>Click Me!</button>
Enter fullscreen modeExit fullscreen mode

😨 We do lots of things, we are almost done.


Finally 4. It's about Routing & Navigation

ember g route welcome
Enter fullscreen modeExit fullscreen mode
  1. Openapp/router.js and update
this.route('welcome',{path:'/:app_code'},function(){});
Enter fullscreen modeExit fullscreen mode
  1. Openapp/routes/welcome.js and includes
importRoutefrom'@ember/routing/route';exportdefaultclassWelcomeRouteextendsRoute{beforeModel(transition){console.log('message:-',transition);}model(params){console.log('This is the dynamic segment data:',params);}}
Enter fullscreen modeExit fullscreen mode
  1. finally openapp/templates/application.hbs
<LinkToclass=""@route="welcome"@model="myappcode">Welcome</LinkTo>
Enter fullscreen modeExit fullscreen mode

👌 Congratulations!. & Thank You!
Feel free to comments, If you have any issues & queries.


References

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I’m very much eager about new tools and technologies. I love to work with the R&D Team. Till now my findings, I believe nothing is impossible just need focus, dedication, and time.
  • Location
    Dhaka, Bangladesh
  • Work
    Full-Stack Software Engineer
  • Joined

More fromSadhan Sarker

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp