Skip to content

Instantly share code, notes, and snippets.

@briarsweetbriar
Created January 20, 2022 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briarsweetbriar/5bc91e04538d15ccdd55f5f352b48beb to your computer and use it in GitHub Desktop.
Save briarsweetbriar/5bc91e04538d15ccdd55f5f352b48beb to your computer and use it in GitHub Desktop.
New Twiddle
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
export default class ApplicationController extends Controller {
@service('nav-blocker') navBlocker;
appName = 'Ember Twiddle';
@action
toggleNavBlocker() {
this.navBlocker.isBlocking = !this.navBlocker.isBlocking;
}
}
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
const Router = EmberRouter.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('food');
this.route('bard');
});
export default Router;
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default Route.extend({
navBlocker: service('nav-blocker'),
queryParams: {
bardQp: {
refreshModel: true,
},
},
actions: {
willTransition(transition) {
if (this.navBlocker.isBlocking) {
transition.abort();
}
}
}
});
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default Route.extend({
navBlocker: service('nav-blocker'),
queryParams: {
foodQp: {
refreshModel: true,
},
},
actions: {
willTransition(transition) {
if (this.navBlocker.isBlocking) {
transition.abort();
}
}
}
});
import Service from '@ember/service';
import { tracked } from '@glimmer/tracking';
export default class NavBlocker extends Service {
@tracked isBlocking = false
};
<h1>Welcome to "Maximum call stack" Hell</h1>
<p>To reproduce:</p>
<ol>
<li>Open your console</li>
<li>Click on a "w/ Query Params" link</li>
<li>Click "Block Transitions"</li>
<li>Click on any other link</li>
<li>Note the "Maximum call stack" error in your console</li>
</ol>
<button {{on "click" (action this.toggleNavBlocker)}}>
{{#if this.navBlocker.isBlocking}}
Unblock Transitions
{{else}}
Block Transitions
{{/if}}
</button>
<br>
<br>
<hr>
<br>
<br>
<table>
<tr>
<td>
<LinkTo @route="food" @query={{hash foodQp=null}}>Food</LinkTo>
</td>
<td>
<LinkTo @route="bard" @query={{hash bardQp=null}}>Bard</LinkTo>
</td>
</tr>
<tr>
<td>
<LinkTo @route="food" @query={{hash foodQp=true}}>Food (w/ QueryParams)</LinkTo>
</td>
<td>
<LinkTo @route="bard" @query={{hash bardQp=true}}>Bard (w/ QueryParams)</LinkTo>
</td>
</tr>
</table>
<br>
<br>
{{outlet}}
<br>
<br>
<img src="https://149658804.v2.pressablecdn.com/wp-content/uploads/2021/08/image2.jpg" />
<img src="https://images.squarespace-cdn.com/content/v1/53b839afe4b07ea978436183/1608506169128-S6KYNEV61LEP5MS1UIH4/traditional-food-around-the-world-Travlinmad.jpg" />
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js",
"ember": "3.18.1",
"ember-template-compiler": "3.18.1",
"ember-testing": "3.18.1"
},
"addons": {
"@glimmer/component": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment