ampersandjs / examples Goto Github PK
View Code? Open in Web Editor NEWA collection of example apps/patterns using ampersand
License: MIT License
A collection of example apps/patterns using ampersand
License: MIT License
You've got an app written using AMD and require.js. You'd love to use ampersand and all its awesomeness. How do you do it?
I propose an example for those in my situation, using the solution I found useful. Basically I used browerify in my build process to process a simple proto
file.
var underscoreMixin = require('ampersand-collection-underscore-mixin');
module.exports = {
State : require('ampersand-state'),
Registry : require('ampersand-registry'),
View: require('ampersand-view'),
Model: require('ampersand-model'),
Collection : require('ampersand-rest-collection').extend(underscoreMixin)
};
I then run browserify in my gulp as a dependent task:
gulp.task('bundleAmpersand', function() {
return gulp.src('./client/core/assets/js/libs/ampersand-proto.js')
.pipe(plugins.browserify({
debug : true,
standalone : 'ampersand',
external : ["jquery", "underscore"]
}))
.pipe(plugins.rename('ampersand-bundle.js'))
.pipe(gulp.dest('./client/core/assets/js/libs'));
});
and config require.js to use ampersand
in its config file:
requirejs.config({
paths : {
// rest of config paths:
ampersand : 'core/assets/js/libs/ampersand-bundle'
},
shim : {
ampersand : ['lodash', 'jquery'],
}
});
Then use happily:
// using nicer define vs the array type definition
define(function(require){
var Ampersand = require('ampersand');
var MyModel = Ampersand.Model.extend({
/// model def
});
return MyModel;
});
Proposed example would flesh this out with a real project. But mostly with a heavy emphasis on the readme.md since everyone's require.js configuration is slightly different.
Tried on Windows windows-npm-debug.txt with node 4/5/master and Ubuntu 14_04 build.ubuntu.txt with node 5.
Build errors regarding node-gyp.
Deleting all the restrictions on the versions in package.json enables npm install to work on both platforms.
npm start then fails debug_start.txt
Thanks for sharing these patterns. I've seen the internals
object in a few hapijs projects. Is the internals
object's purpose just to encapsulate application level code?
Hey @latentflip I was just wondering how does the change event get triggered for the domthing example? I'm having a hard time understanding this. I've looked at ampersand-state
but I'm either too tired or the change is not being triggered there. Thank you.
/cc @HenrikJoreteg
Thanks guys.
If you're using bindings, you don't need anything more than straight up html for templates, so something like: https://github.com/JohnPostlethwait/stringify makes this really easy to just require templates directly from a view.
This just came up in gitter, so a simple example of this would be useful, assigning to me, unless anyone else wants to do it @CrowdHailer?
It's come up in chat a few times and ampersand handles this quite well.
There's a basic gist of it here: https://gist.github.com/HenrikJoreteg/e76d72b0559ae9b6061b but it'd need to be polished up a bit.
http://hapijs.com/api for reference
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.