Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
klembot committed Dec 15, 2017
2 parents fcc4693 + 1c293d5 commit 5c15d74
Show file tree
Hide file tree
Showing 14 changed files with 15,182 additions and 36 deletions.
15,041 changes: 15,041 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

15 changes: 5 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Twine",
"version": "2.2.0-beta1",
"version": "2.2.0",
"author": "Chris Klimas <[email protected]>",
"description": "a GUI for creating nonlinear stories",
"license": "GPL-3.0",
Expand Down Expand Up @@ -30,20 +30,15 @@
"watch": "webpack -d --progress --watch"
},
"dependencies": {
"babel-loader": "^6.2.10",
"blob-polyfill": "^1.0.20150320",
"browser-saveas": "^1.0.0",
"codemirror": "^5.5.0",
"core-js": "^2.4.0",
"ejs-html-loader": "^2.0.2",
"extract-text-webpack-plugin": "^2.0.0-rc.3",
"fastclick": "^1.0.6",
"font-awesome": "^4.3.0",
"html-webpack-plugin": "^2.28.0",
"jed": "^1.1.0",
"jsonp": "^0.2.1",
"jszip": "^2.5.0",
"karma-webpack": "^2.0.4",
"lodash.escape": "^4.0.1",
"lodash.uniq": "^4.5.0",
"lodash.values": "^4.3.0",
Expand Down Expand Up @@ -76,7 +71,7 @@
"ejs-loader": "^0.3.0",
"eslint": "^3.10.2",
"estraverse": "^4.2.0",
"extract-text-webpack-plugin": "^2.1.2",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^0.11.2",
"fs-extra": "^1.0.0",
"glob": "^7.1.1",
Expand All @@ -92,7 +87,7 @@
"less-plugin-autoprefix": "^1.5.1",
"less-plugin-clean-css": "^1.5.1",
"mocha": "^3.2.0",
"mocha-webpack": "^0.7.0",
"mocha-webpack": "^1.0.1",
"mock-local-storage": "^1.0.4",
"null-loader": "^0.1.1",
"nw-builder": "^3.2.0",
Expand All @@ -103,8 +98,8 @@
"sinon": "^3.2.1",
"style-loader": "^0.18.2",
"url-loader": "^0.5.9",
"webpack": "^3.5.5",
"webpack-dev-server": "^2.7.1",
"webpack": "^3.10.0",
"webpack-dev-server": "^2.9.5",
"webpack-node-externals": "^1.6.0",
"yargs": "^6.6.0"
}
Expand Down
10 changes: 5 additions & 5 deletions src/data/actions/story-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ const actions = module.exports = {
},
{
name: 'Harlowe',
url: 'story-formats/harlowe-2.0.1/format.js',
version: '2.0.1',
url: 'story-formats/harlowe-2.1.0/format.js',
version: '2.1.0',
userAdded: false
},
{
Expand All @@ -199,8 +199,8 @@ const actions = module.exports = {
},
{
name: 'SugarCube',
url: 'story-formats/sugarcube-2.18.0/format.js',
version: '2.18.0',
url: 'story-formats/sugarcube-2.21.0/format.js',
version: '2.21.0',
userAdded: false
}
];
Expand All @@ -223,7 +223,7 @@ const actions = module.exports = {
setPref(
store,
'defaultFormat',
{ name: 'Harlowe', version: '2.0.1' }
{ name: 'Harlowe', version: '2.1.0' }
);
}

Expand Down
16 changes: 8 additions & 8 deletions src/data/actions/story-format.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ describe('story format actions module', () => {
expect(created['Harlowe-1.2.4']).to.exist;
expect(created['Harlowe-1.2.4'].url).to.equal('story-formats/harlowe-1.2.4/format.js');
expect(created['Harlowe-1.2.4'].userAdded).to.be.false;
expect(created['Harlowe-2.0.1']).to.exist;
expect(created['Harlowe-2.0.1'].url).to.equal('story-formats/harlowe-2.0.1/format.js');
expect(created['Harlowe-2.0.1'].userAdded).to.be.false;
expect(created['Harlowe-2.1.0']).to.exist;
expect(created['Harlowe-2.1.0'].url).to.equal('story-formats/harlowe-2.1.0/format.js');
expect(created['Harlowe-2.1.0'].userAdded).to.be.false;
expect(created['Paperthin-1.0.0']).to.exist;
expect(created['Paperthin-1.0.0'].url).to.equal('story-formats/paperthin-1.0.0/format.js');
expect(created['Paperthin-1.0.0'].userAdded).to.be.false;
Expand All @@ -76,9 +76,9 @@ describe('story format actions module', () => {
expect(created['SugarCube-1.0.35']).to.exist;
expect(created['SugarCube-1.0.35'].url).to.equal('story-formats/sugarcube-1.0.35/format.js');
expect(created['SugarCube-1.0.35'].userAdded).to.be.false;
expect(created['SugarCube-2.18.0']).to.exist;
expect(created['SugarCube-2.18.0'].url).to.equal('story-formats/sugarcube-2.18.0/format.js');
expect(created['SugarCube-2.18.0'].userAdded).to.be.false;
expect(created['SugarCube-2.21.0']).to.exist;
expect(created['SugarCube-2.21.0'].url).to.equal('story-formats/sugarcube-2.21.0/format.js');
expect(created['SugarCube-2.21.0'].userAdded).to.be.false;
});

it('sets default formats with repairFormats()', () => {
Expand All @@ -95,7 +95,7 @@ describe('story format actions module', () => {
actions.repairFormats(formatsStore);

expect(formatsStore.dispatch.calledWith(
'UPDATE_PREF', 'defaultFormat', { name: 'Harlowe', version: '2.0.1' }
'UPDATE_PREF', 'defaultFormat', { name: 'Harlowe', version: '2.1.0' }
)).to.be.true;
expect(formatsStore.dispatch.calledWith(
'UPDATE_PREF', 'proofingFormat', { name: 'Paperthin', version: '1.0.0' }
Expand Down Expand Up @@ -131,7 +131,7 @@ describe('story format actions module', () => {
{ name: 'Paperthin', version: '1.0.0' },
{ name: 'Snowman', version: '1.3.0' },
{ name: 'SugarCube', version: '1.0.35' },
{ name: 'SugarCube', version: '2.18.0' }
{ name: 'SugarCube', version: '2.21.0' }
]
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/nw/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module.exports = {
const patchStore = require('./patches/store');
const patchStoryListToolbar = require('./patches/story-list-toolbar');
const patchWelcomeView = require('./patches/welcome-view');
const saveQueue = require('./save-queue');
const storyFile = require('./story-file');

const win = gui.Window.get();
Expand Down Expand Up @@ -163,6 +164,7 @@ module.exports = {
startupTask = 'setting up shutdown tasks';

gui.Window.get().on('close', function() {
saveQueue.flush();
directories.unlockStories();
this.close(true);
});
Expand Down
17 changes: 7 additions & 10 deletions src/nw/patches/store/file-persistence.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const StoryFile = require('../../story-file');
const saveQueue = require('../../save-queue');
const storyFile = require('../../story-file');

let enabled = true;
let previousStories;

module.exports = store => {
previousStories = store.state.story.stories;
saveQueue.attachStore(store);

store.subscribe((mutation, state) => {
if (!enabled) {
Expand All @@ -19,7 +21,7 @@ module.exports = store => {

case 'CREATE_STORY':
case 'IMPORT_STORY':
StoryFile.save(
storyFile.save(
state.story.stories.find(
story => story.name === mutation.payload[0].name
),
Expand All @@ -28,7 +30,7 @@ module.exports = store => {
break;

case 'DELETE_STORY':
StoryFile.delete(previousStories.find(
storyFile.delete(previousStories.find(
story => story.id === mutation.payload[0]
));
break;
Expand All @@ -48,7 +50,7 @@ module.exports = store => {
*/

if (mutation.type === 'UPDATE_STORY' && mutation.payload[1].name) {
StoryFile.delete(
storyFile.delete(
previousStories.find(
story => story.id === mutation.payload[0]
),
Expand All @@ -58,12 +60,7 @@ module.exports = store => {

/* Save changes as normal. */

StoryFile.save(
state.story.stories.find(
story => story.id === mutation.payload[0]
),
state.appInfo
);
saveQueue.queue(mutation.payload[0]);
break;
}

Expand Down
64 changes: 64 additions & 0 deletions src/nw/save-queue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Manages a queue for saving story files. We can't save story files immediately as
the user edits them, because the changes come so rapidly. Instead, we queue
saves up and periodically flush the queue.
You *must* call flush() on this module before the application closes to prevent
data loss.
*/

const StoryFile = require('./story-file');

let idQueue = [];
let flushTimeout;

const SaveQueue = module.exports = {
/* How long to wait to flush the queue, in milliseconds. */

delay: 10000,

/*
Attaches to a Vuex store, for retrieval of stories. Must be called before
any flush() call.
*/

attachStore(store) {
SaveQueue.store = store;
},

/*
Queues an story to be saved. Repeated requests to save the same story don't
change the queue, but they do reset the delay to save.
*/

queue(id) {
if (flushTimeout) {
window.clearTimeout(flushTimeout);
}

flushTimeout = window.setTimeout(SaveQueue.flush, SaveQueue.delay);

if (idQueue.indexOf(id) === -1) {
idQueue.push(id);
}
},

/*
Saves all pending stories.
*/

flush() {
if (!SaveQueue.store) {
throw new Error('No store has been set for this save queue');
}

while (idQueue.length > 0) {
const id = idQueue.pop();
const story = SaveQueue.store.state.story.stories.find(
s => s.id === id
);

StoryFile.save(story, SaveQueue.store.state.appInfo);
}
}
};
47 changes: 47 additions & 0 deletions src/nw/save-queue.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { expect } = require('chai');
const { stub } = require('sinon');
const storyFile = require('./story-file');
const saveQueue = require('./save-queue');

describe('SaveQueue', () => {
let fakeStore = {
state: {
story: {
stories: [
{
name: 'test',
id: 'not-a-real-id'
}
]
}
}
};

beforeEach(() => {
stub(storyFile, 'save');
});

afterEach(() => {
storyFile.save.restore();
});

it('triggers a save action after its delay elapses', done => {
storyFile.save.callsFake(story => {
expect(story.name).to.equal('test');
expect(story.id).to.equal('not-a-real-id');
done();
});
saveQueue.attachStore(fakeStore);
saveQueue.delay = 100;
saveQueue.queue('not-a-real-id');
});

it('immediately saves on flush()', () => {
saveQueue.attachStore(fakeStore);
saveQueue.delay = 10000;
saveQueue.queue('not-a-real-id');
saveQueue.flush();
expect(storyFile.save.calledOnce);
expect(storyFile.save.firstCall.calledWith('not-a-real-id'));
});
});
2 changes: 0 additions & 2 deletions story-formats/harlowe-2.0.1/format.js

This file was deleted.

2 changes: 2 additions & 0 deletions story-formats/harlowe-2.1.0/format.js

Large diffs are not rendered by default.

File renamed without changes
File renamed without changes.

Large diffs are not rendered by default.

File renamed without changes

0 comments on commit 5c15d74

Please sign in to comment.