mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-27 08:28:50 +02:00
ok optimistic parsing going
This commit is contained in:
parent
8a1986a923
commit
f8b9c8b583
9 changed files with 1509 additions and 1317 deletions
2738
build/bundle.js
2738
build/bundle.js
File diff suppressed because it is too large
Load diff
|
@ -116,11 +116,18 @@ var init = function() {
|
|||
$('#commandTextField').on('keyup', makeKeyListener('keyup'));
|
||||
$(window).trigger('resize');
|
||||
|
||||
/* hacky demo functionality */
|
||||
// demo functionality
|
||||
if (/\?demo/.test(window.location.href)) {
|
||||
setTimeout(function() {
|
||||
eventBaton.trigger('commandSubmitted', "gc; git checkout HEAD~1; git commit; git checkout -b bugFix; gc; gc; git rebase -i HEAD~2; git rebase master; git checkout master; gc; gc; git merge bugFix; help");
|
||||
}, 500);
|
||||
sandbox.mainVis.customEvents.on('gitEngineReady', function() {
|
||||
eventBaton.trigger(
|
||||
'commandSubmitted',
|
||||
[
|
||||
"gc; git checkout HEAD~1; git commit; git checkout -b bugFix; gc;",
|
||||
"git rebase -i HEAD~3; git rebase master; git checkout master; gc;",
|
||||
"git merge bugFix; levels; level rebase1; delay 3000;",
|
||||
"git checkout -b win; git commit; help"
|
||||
].join(''));
|
||||
});
|
||||
}
|
||||
if (/(iPhone|iPod|iPad).*AppleWebKit/i.test(navigator.userAgent)) {
|
||||
setTimeout(function() {
|
||||
|
|
|
@ -351,3 +351,4 @@ var LevelBuilder = Level.extend({
|
|||
});
|
||||
|
||||
exports.LevelBuilder = LevelBuilder;
|
||||
exports.regexMap = regexMap;
|
||||
|
|
|
@ -427,4 +427,4 @@ var Level = Sandbox.extend({
|
|||
});
|
||||
|
||||
exports.Level = Level;
|
||||
|
||||
exports.regexMap = regexMap;
|
||||
|
|
|
@ -4,8 +4,9 @@ var GitCommands = require('../git/commands');
|
|||
var SandboxCommands = require('../level/SandboxCommands');
|
||||
|
||||
// more or less a static class
|
||||
function ParseWaterfall(options) {
|
||||
var ParseWaterfall = function(options) {
|
||||
options = options || {};
|
||||
this.options = options;
|
||||
this.shortcutWaterfall = options.shortcutWaterfall || [
|
||||
GitCommands.shortcutMap
|
||||
];
|
||||
|
@ -15,11 +16,19 @@ function ParseWaterfall(options) {
|
|||
SandboxCommands.instantCommands
|
||||
];
|
||||
|
||||
this.parseWaterfall = options.parseWaterfall || [
|
||||
// defer the parse waterfall until later...
|
||||
};
|
||||
|
||||
ParseWaterfall.prototype.initParseWaterfall = function() {
|
||||
// by deferring the initialization here, we dont require()
|
||||
// level too early (which barfs our init)
|
||||
this.parseWaterfall = this.options.parseWaterfall || [
|
||||
GitCommands.parse,
|
||||
SandboxCommands.parse
|
||||
SandboxCommands.parse,
|
||||
SandboxCommands.getOptimisticLevelParse(),
|
||||
SandboxCommands.getOptimisticLevelBuilderParse()
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
ParseWaterfall.prototype.clone = function() {
|
||||
return new ParseWaterfall({
|
||||
|
@ -30,6 +39,9 @@ ParseWaterfall.prototype.clone = function() {
|
|||
};
|
||||
|
||||
ParseWaterfall.prototype.getWaterfallMap = function() {
|
||||
if (!this.parseWaterfall) {
|
||||
this.initParseWaterfall();
|
||||
}
|
||||
return {
|
||||
shortcutWaterfall: this.shortcutWaterfall,
|
||||
instantWaterfall: this.instantWaterfall,
|
||||
|
@ -83,6 +95,10 @@ ParseWaterfall.prototype.processInstant = function(commandStr, instantCommands)
|
|||
};
|
||||
|
||||
ParseWaterfall.prototype.parseAll = function(commandStr) {
|
||||
if (!this.parseWaterfall) {
|
||||
this.initParseWaterfall();
|
||||
}
|
||||
|
||||
var toReturn = false;
|
||||
_.each(this.parseWaterfall, function(parseFunc) {
|
||||
var results = parseFunc(commandStr);
|
||||
|
|
|
@ -60,3 +60,23 @@ var regexMap = {
|
|||
exports.instantCommands = instantCommands;
|
||||
exports.parse = util.genParseCommand(regexMap, 'processSandboxCommand');
|
||||
|
||||
// optimistically parse some level and level builder commands; we do this
|
||||
// so you can enter things like "level intro1; show goal" and not
|
||||
// have it barf. when the
|
||||
// command fires the event, it will check if there is a listener and if not throw
|
||||
// an error
|
||||
|
||||
// note: these are getters / setters because the require kills us
|
||||
exports.getOptimisticLevelParse = function() {
|
||||
return util.genParseCommand(
|
||||
require('../level').regexMap,
|
||||
'processLevelCommand'
|
||||
);
|
||||
};
|
||||
|
||||
exports.getOptimisticLevelBuilderParse = function() {
|
||||
return util.genParseCommand(
|
||||
require('../level/builder').regexMap,
|
||||
'processLevelBuilderCommand'
|
||||
);
|
||||
};
|
||||
|
|
|
@ -91,6 +91,19 @@ var CommandBuffer = Backbone.Model.extend({
|
|||
}
|
||||
|
||||
var Main = require('../app');
|
||||
var eventBaton = Main.getEventBaton();
|
||||
|
||||
var numListeners = eventBaton.getNumListeners(eventName);
|
||||
if (!numListeners) {
|
||||
var Errors = require('../util/errors');
|
||||
command.set('error', new Errors.GitError({
|
||||
msg: 'That command is valid, but not supported in this current environment!' +
|
||||
' Try entering a level or level builder to use that command'
|
||||
}));
|
||||
deferred.resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
Main.getEventBaton().trigger(eventName, command, deferred);
|
||||
},
|
||||
|
||||
|
|
|
@ -42,6 +42,11 @@ EventBaton.prototype.trigger = function(name) {
|
|||
toCall.func.apply(toCall.context, argsToApply);
|
||||
};
|
||||
|
||||
EventBaton.prototype.getNumListeners = function(name) {
|
||||
var listeners = this.eventMap[name] || [];
|
||||
return listeners.length;
|
||||
};
|
||||
|
||||
EventBaton.prototype.getListenersThrow = function(name) {
|
||||
var listeners = this.eventMap[name];
|
||||
if (!listeners || !listeners.length) {
|
||||
|
|
|
@ -457,9 +457,11 @@ var NextLevelConfirm = ConfirmCancelTerminal.extend({
|
|||
]);
|
||||
}
|
||||
|
||||
options.modalAlert = {
|
||||
markdowns: markdowns
|
||||
};
|
||||
options = _.extend(
|
||||
{},
|
||||
options,
|
||||
{ markdowns: markdowns }
|
||||
);
|
||||
|
||||
NextLevelConfirm.__super__.initialize.apply(this, [options]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue