requirejs

How to properly require files into another file

◇◆丶佛笑我妖孽 提交于 2019-12-25 00:50:28
问题 I have a bunch of js script files that use require to require the same series of libraries, etc.' let path = require('path'); let _ = require('underscore'); I want to put all these requirements into a separate library file that I can then reuse amongst the files that need them. I though I could do something like this: var common = function() { this.requireFiles = function() { let path = require('path'); let _ = require('underscore'); ... } }; export.common = common; However, when I want to

use a typescript module/class in the browser and in the server (Node.Js)

杀马特。学长 韩版系。学妹 提交于 2019-12-25 00:24:31
问题 How would I use the same typescript class or module in a client side javascript file and in a server side node.js file? I found a solution here where you manually create the exports variable instead of using TypeScript's export keyword but then you lose the type information for the class when you include it in node.js with the require keyword. 回答1: You can cast what comes out of the require function since you know what it's going to be. module Lib { export class Alpha { bravo: number = 1; } }

jQuery plugin + AMD = how to access functions?

守給你的承諾、 提交于 2019-12-24 21:57:09
问题 I am wrapping up my jQuery plugin in an AMD environment. This is my boilerplate, !function(root, factory) { if (typeof define === 'function' && define.amd) { define(['jquery'], factory); } else { factory(root.jQuery); } }(this, function($) { var defaults = { target: '' }; var myPlugin = function(options) { options = $.extend(true, {}, defaults, options); return options; }; myPlugin.prototype = { init: function(options) { return options; } }; $.fn.myPlugin = myPlugin; }); console.log($.fn

require. how to pass a model to a view (backbone)

耗尽温柔 提交于 2019-12-24 21:16:36
问题 I'm using require.js with backbone. My question: is how do I fetch.() my model from within my view. What I have tried is below, however I get the error 'Campaign is undefined'. I think I'm very close: Model: define([ 'underscore', 'backbone' ], function(_, Backbone) { var Campagin = Backbone.Model.extend({ urlRoot: '/api/v1/campaign/' }); return Campagin; }); View: define([ 'jquery', 'underscore', 'backbone', 'views/RewardView', 'views/FriendRewardView', 'models/CampaginModel', 'text

Access global variables from Require.js in the Chrome Developer Console

不羁的心 提交于 2019-12-24 18:28:52
问题 I am creating an ASP.NET single-page application, and have a require.js config file that runs on application start, referencing jQuery, Sammy.js, and knockout.js. I have created shims for the three third-party libraries to allow me to access them on a global level: require.config({ paths: { "jquery": "/Scripts/jquery-2.1.4.min", "sammy": "/Scripts/sammy-0.7.5.min", "knockout": "/Scripts/knockout-3.3.0", "text": "/Scripts/text", "appVm": "/Scripts/app/appViewModel" }, shim: { "jquery": {

No errors thrown/displayed when in a deferred callback

谁说我不能喝 提交于 2019-12-24 17:46:14
问题 We're building a project with RequireJS and Node, and reusing modules both server and client side. It's going pretty good so far (some small kinks to work out). An issue seems to be that errors inside a deferred callback don't ever get displayed in the node console (or in any other way for that matter). Making it very hard to debug. asdasdasd(); // Throws error, function is undefined, as intended this.loadOrganization(organization_key, true).then(function(org) { asdasdasd(); // No error

Backbone Marionette and ICanHaz (Mustache) templates configuration

天涯浪子 提交于 2019-12-24 16:38:58
问题 I'm migrating a Backbone basic app to Marionette and I would like to use ICanHaz.js as a template system (based on Mustache). I'm using AMD and Require.js and the only way to make ICanHaz.js working with it and Backbone was to use jvashishtha's version. I first implemented the app in pure Backbone style. In particular I used to load each template as raw strings with the Require.js' text plugin and then add the template to the ich object. This create a method in ich object that has the same

Knockout component fails if element removed before template returned

与世无争的帅哥 提交于 2019-12-24 16:26:54
问题 I have a KO custom binding which adds a component to the page (as a virtual element but i don't think this matters) and then applies a view model to it. The component loads it's template via require from the server. However during load I am getting a problem where the custom binding is updated and removing the element from the page (I want to have it tidy it's self up if not required). This results in a race condition - if the asychronous lookup for the template has not finished before the

How to test spa js modules with resharper testr jasmin?

橙三吉。 提交于 2019-12-24 16:03:24
问题 After reading about javascript unit testing / bdd in VS I found that you could use a combination of: - ReSharper - support for PhantomJS headless + Jasmine/QUnit - Testr - mock Require dependencies I used Jasmine in a test script and was able to successfully run some simple tests, with functions declared in the same file. However, I could not find / build a working end to end example for testing a js module with dependencies. I am trying to build on the example used in the SPA Jumpstart

How to use jquery ui with requireJS and knockout-sortable?

旧街凉风 提交于 2019-12-24 15:08:04
问题 I'm trying to use requireJS to manage dependencies in my first ever single-page javascript app. Having never used requireJS before, I'm struggling with something that I think is quit basic. My project uses knockoutJS, and an addon called knockout-sortable, which provides knockout bindings for the jquery ui 'sortable' plugin. It all works fine when I just load jquery ui, knockout and everything else without requireJS. My require main.js looks like this: require.config({ baseUrl: '/Scripts',