Comments (16)
helpers/time.js:
var helperFunction = function() {
// does stuff
};
export default helperFunction;
And also:
helpers/time => Ember.Handlebars.registerBoundHelper('time', helperFunction);
from ember-app-kit.
Just thinking out loud here, but in case we want to support the option of people's helper functions in /helpers/**/*.js
using registerHelper
vs registerBoundHelper
(which people will admittedly want to use 90% of the time), we could at some point allow for something like this:
var helperFunction = function() {
// does stuff
};
helperFunction.raw = true; // use registerHelper
export default helperFunction;
Thoughts?
from ember-app-kit.
you can have both a default, and default + named exports.
export unboundHelper;
export default <name of helper>;
if we detect unboundHelper we prioritize it.
from ember-app-kit.
-
I want to stick to the one file == one export == one module system we have going, seems weird to break that for helpers in particular
-
Sticking config on the function could work, or some other kind of configuration object the resolver could handle, i.e.:
export default { name: "myHelper", fn: myFunction, raw: true }
(ugly though)
-
Do we want to enforce file name == helper name? Bad for people who like camelCase.
from ember-app-kit.
My concerns:
- I believe pretty strongly helpers should be
camelCase
, if they aredash-erized
its not obvious where to go looking in the JS when staring at a template. Dashes, components; camelCase, helper. - There are actually three types of helpers,
registerHelper
,registerBoundHelper
, and justhelper
which can take an Ember.View as the second argument. Anything we do to export something will feel awkward I think.
I'm happy to just have helper files register themselves. Ember.Handlebars.registerHelper
and then the ember docs actually mean something.
from ember-app-kit.
So, I'm working on container-izing helpers with @twokul right now, and just so we're all on the same page, the plan is to have helpers be stored as functions on the container. For bound helpers (most of them), we're splitting the bulk of the registerBoundHelper
code into makeBoundHelper
, which, given a function, will return a function that can be used as a bound helper and therefore stored on the container. I think this is the right way to go; it'll be up to EAK and any other approaches that make use of the container to determine how and whether a helper is bound vs raw vs whatever, and decide what gets stashed on the container.
(this is me not weighing in on how EAK should expose it; just making it clear what is EAK vs Ember's responsibility. lemme know if i'm craycray)
from ember-app-kit.
Check out the recently updated emberjs/ember.js#3329 for an implementation on the above.
Also folks, remember that registerBoundHelper
has optional 3-Nth params for dependent keys that'll be observed on the first param of a bound helper invocation that will cause a re-render.
@thomasboyt maybe i'm being a clown but what's the difference b/w
export default { name: "myHelper", fn: myFunction, raw: true }
and
export name "myHelper";
export fn myFunction;
export raw true;
(I'm admittedly not 100% up to date on es6 or what the transpilers are capable so maybe this is silly, but seems to me there's not different between multiple exports and a single default config export)
from ember-app-kit.
said in irc, but here for ref too: EAK's resolver only imports the default export of a module. difference is:
export default { name: "myHelper", fn: myFunction, raw: true }
// imported as
import optsHash from "module";
export var name = "myHelper";
export var fn = myFunction;
export var raw = true;
// imported as
import {name, fn, raw} from "module";
eak can only deal w/ the former. resolver is going to need special behavior for dealing with helpers either way, so maybe could be set up to use named exports instead. once es6 transpiler v2 hits you'll be able to use named & default exports together so could even do
export default helperFn;
export var name = "foo";
export var raw = true;
export var dependent = ["foo", "bar", "baz"]
or something
from ember-app-kit.
Been through the discussion, but can't figure out how one's supposed to define the helpers.
Is there some concrete example, which can be integrated with the wiki ?
from ember-app-kit.
@MeirKriheli This https://github.com/nihique/fire-up-ember-app-kit is a little bit out of date, but was very helpful for me to get started.
I agree, it would be nice to have this in the wiki.
from ember-app-kit.
I'm also not sure what the current state here is. Fwiw, I would like to share this helper I've used a few times:
// Translated from CoffeeScript and un-tested in the wild, so take care.
function importTo(namespace, directory, suffix){
var directoryFinder = new RegExp("\/"+directory+"\/");
Ember.keys(define.registry).filter(function(key){
return directoryFinder.test(key);
}).forEach(function(key){
var imported = requireModule(key);
var className = key.split("/")[2].classify() + (suffix || '');
namespace[className] = imported;
});
}
// Map 'appkit/models/post' to App.Post
importTo(App, "models");
// Map 'appkit/components/button_bar' to App.ButtonBarComponent
importTo(App, "components", "Component");
// Don't worry about where the helpers go, just require them.
importTo({}, 'helpers');
Some of this isn't even necessary anymore due to the rampant containerization of all the things, but it works well as a stop-gap for pre-container objects, or migrating old code that still expects global App.FooView
and such (so long as you do not require dependency injection on them).
from ember-app-kit.
How would you write this exact code in EAK (from the ember guides)?
Ember.Handlebars.helper('highlight', function(value, options) {
var escaped = Handlebars.Utils.escapeExpression(value);
return new Handlebars.SafeString('<span class="highlight">' + escaped + '</span>');
});
Also, if it is relevant, trying to use helper inside component template. e.g.
templates/components/my-component.hbs
{{highlight name}}
I get 'Handlebars' is not defined.
errors. Not sure what I have to do. Import Handlebars? Anybody have a working example?
from ember-app-kit.
Most likely the handlebars not defined errors are actually from JSHint.
You can add it to the .jshintrc file (near the top) so that JSHint knows about the 'Handlebars' global.
You could also use 'Ember.Handlebars' (I think).
from ember-app-kit.
Ahh thank you. Makes sense. Seems this should be included in the standard setup of EAK. Probably also want to add Ember Data if and when that become standard part of EAK.
from ember-app-kit.
emberjs/ember.js#3329 will allow ember to resolve some helpers directly.
from ember-app-kit.
#3329 was merged.
from ember-app-kit.
Related Issues (20)
- Does EAK Support Inheritance With Controllers? HOT 3
- Suggestion: Defer loading of JavaScript HOT 1
- Recommended Folder Structure Using EAK HOT 4
- Migrating to Ember-CLI HOT 17
- Deploying to a non-root directory HOT 3
- Trouble with NPM scripts HOT 1
- 'grunt test:server' not work HOT 1
- Extending Store In EAK HOT 4
- EAK: Where do we place {{partials}} ? HOT 2
- ./config/environment.js example HOT 7
- `Cannot find module..." HOT 3
- Migrating to Ember-CLI Screencast HOT 2
- Importing shared ES6 modules futuristically HOT 2
- Added bootstrap-sass-official, Now Can't Push to Heroku HOT 2
- Stub API not working with server:dist task
- Transition into the loading substate
- Allow Ember Init and Generate for Coffeescript HOT 1
- Production build failed (grunt:dist) on fresh clone of EAK HOT 1
- Cannot deploy the 'ember app kit' app to heroku
- Update Ember CLI Migration Guide HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ember-app-kit.