I have a JSON file I use to store dialogue for a game. However, the changes I make to this JSON file are sometimes not reflected in my game even after hard reloads (I've been doing ctrl+shift+r or shift+F5 for this). I have made sure the changes to the JSON file are saved.
I have this.load.json('dialogue', 'assets/dialogue.json'); in preload(), and this.dialogue = this.cache.json.get('dialogue'); in create().
When I try copy+pasting the contents to a new different file (e.g. dialogue-2.json), and update my this.load.json() to reflect the new file name, the changes do get loaded.
The problem is that phaser doesn't automatic start the loading files, except in the preload function.
If you want to load files in other functions you need to call the start method of the LoadPlugin. Here the link to the official documentation.
The code should look something like this:
function create(){
// some code here ...
this.load.json(/* key and file...*/);
// start the loading of the enqueued files
this.load.start();
// some code here...
}
..., than the files should get loaded.
Update (copied form comments):
to check (and as a tempoary quickfix) if your problem, is a caching issue from the Webserver or browser or ..., you can load the file with a "dynamic" Url.
Just a load the file with a questionmark and random number added to the url, so that each call to the json uses aunique Url.
For Example like this:
this.load.json('dialogue', 'assets/dialogue.json?' + Math.random());
If this solves the problem, there is a caching problem. It could be in the browser, or simply caused by serviceworker or on the webserver.
Related
I've got images inserting into the editor as base64 encoded images (uploader option insertImageAsBase64URI is set to true). However, I'd like to call a function after the image has been inserted and also read the source filename for the inserted image.
I'm new to the JODIT editor, it seems great so far, but I need to tweak it a bit and am not sure how to register an event callback for this, or if there is another/better way. Any help is appreciated!
I think the best solution is to fork JODIT in github and edit the code. For some reason, however, I have been unable to build the code on my mac laptop for at least a couple of reasons (missing file in node module, fixed, and a build error "TypeError: require(...) is not a function" that may indicate circular dependencies in node modules?). Anyway, I found a complete and limited "HACK" for my needs and that is to actually capture the filename when the file is added by attaching an "onchange" handler function to the JODIT instance's file input element. This works roughly as follows (I'm using jQuery):
var selectedFile = null;
function setSelectedFile(){
$('.jodit').find('input[type="file"]').removeProp('multiple');
$('.jodit').find('input[type="file"]').on('change', function(){
var files = $(this).prop('files');
selectedFile = files[0].name;
});
});
$('.jodit').find('button[aria-label="Insert file"]').on('click',
function(){
setSelectedFile();
}
);
I run something like this after the page has loaded. This works only for the "change" event (where you select a file directly) and I could not figure out how to read the filename after a file is "dropped". Dropping a file does not seem to trigger the "change" event in the file input element. If anyone knows how to get the filename of a dropped file for the JODIT editor I'd appreciate sharing. I will update this if I get around to fixing that.
I'm writing application that you can find here.
It has function that I use to obtain changelog list:
def getChangeLog():
"""
This function downloads changelog from our repository.
:return:
list of change strings
"""
return [change.decode().rstrip() for change in urlopen(
'https://raw.githubusercontent.com/Acmpo6ou/PyQtAccounts/master/change.log')]
Then I can use this list to display changes that are added to my application, all I need to do after making changes and committing them to repository is to update change.log file, so when user will open my application, dialog will be displayed and it will contain changelog.
But for some strange reason urlopen always downloads old change.log file.
Suppose that I have this in my change.log:
Some fixes.
Something is added.
Then suppose that I made some changes, for example serialization standard is changed. So I update my change.log to this:
Changed serialization standard.
When user opens up my application getChangeLog function will obtain change.log file and then it will show dialog with this changelog to user, so user will see something like this:
Changelog for v2.3.6:
* Changed serialization standard.
But for some strange reason this is what will be displayed:
Changelog for v2.3.6:
* Some fixes.
* Something is added.
It displays old change.log
I tried my getChangeLog function in python console and it realy returns the old change.log, I even tried to use urlopen by itself to obtain change.log file and it still obtains the old one.
Most interesting is that if I will call getChangeLog for a few times it starts returning new change.log
I'm absolutely confused, can someone explain me how to fix this?
Probably the reason is that I always call my getChangeLog function, which downloads changelog, at startup. And since I test my app a lot - I launch it a lot, and getChangeLog is called a lot and we download changelog a lot.
So OS thinks: if we download the changelog so often (and it actually changes rarely), then why don't we perform some caching? And instead of actually download changelog OS provides its cached version.
Then, when changelog actually changes OS still provides its cached version and if I call my getChangeLog function a few times the cache expires and it shows new changelog!
I think this is the problem because when I tried to update on my other machine, which I use not so often and hence where I launch my app not so often, and I saw there new changelog.
Mystery solved.
I'm writing a desktop app using electron and react. I want to store some information in a JSON file. I've tried both web-fs and browserify-fs to accomplish this, and neither is working as expected. My setup is as follows
project/app/(react files)
project/index.html
project/js/bundle.js
project/main.js
I'm using watchify to compile all the changes in the react files to the bundle.js file (which is read by index.html).
The following is ran from app.js in project/app/ (which is also where the JSON file is stored)
import * as fs from 'browserify-fs';
...
fs.writeFile('./fileData.json', data, function(err){
if(err)console.log(err);
else console.log("success");
});
'success' is always logged to the console, however the contents of the file is not updated, regardless of how I specify the path.
I've tried './fileData.json'
'/fileData.json'
__dirname + '/fileData.json' (which tells me that __dirname couldn't be found)
(absolute path to fileData.json) (which tells me that /Users could not be found)
After doing the above, if I change the writeFile to readFile and log the contents to the console, the updated file is printed. Even if I delete the fileData.json file, the file is successfully read.
This makes me believe that fs.writeFile() is writing to a different directory, not the one the process is being ran from. Despite this, I cannot find any other fileData.json files anywhere on my computer. There's a couple other weird behaviors:
When logging __filename (which should log the entire filepath), the only thing printed is "/app.js" with no leading file path.
Calling "process.cwd()" just gives me "/"
When calling fs.writeFile() with the full file path "/Users/...." I get a folder not found error
Anyone know what could be causing this behavior and how to fix it?
Edit - I also tried getting the absolute path by adding
var path = require('path')
var appDir = path.resolve('./app');
which again only gives me /app when it should be returning an absolute path
Can you confirm the same behavior when not using browserify-fs? Just use plain old fs. (Note you can do this straight from the Chrome dev tools console).
Looking at browserify-fs's page, it looks like it implements a kind of virtual file system using a dependency called level-filesystem (which uses level db). So the files you're expecting to get created aren't. They're being created within a level db database. You could probably find a level db file somewhere that has the information you're trying to write directly to the file system in it.
For simple writing/reading of a JSON file, I'd recommend https://github.com/sindresorhus/electron-config.
This only occurs in our application which is a ton of code and not something I can put up, nor something anyone would be willing to slog through. So all I can do is describe the error.
We are building our typescript with --amd and have a ton of recursive references between files. It all is working fine until I put this one call in a function:
var di = new moduleDocIterator.DocIterator(null);
With this, the initial load of the main .ts (.js actually) file gives me the null or undefined reference exception on setting up __extends at the top of the generated .js file.
Both the file this call is in and the file moduleDocIterator references have nothing static in them except a couple of strings. The generated .js creates the object for each class but nothing that looks like it is actually executing.
And none of this code is called at the time this happens. This is just the initial load of everything asked for via requireJS.
How do I figure out why it's unhappy?
Suppose I have all of foo.js, foo.coffee, and foo.jsonin the same directory, and I say require './foo' from another (coffeescript) file in that location, what rule governs which one will be loaded?
A short experiment (using require.resolve './foo') would seem to indicate that the javascript file wins over the other two.
Indeed, looking at require.extensions it looks like .js being mentioned there as the first item—but then, object attribute names are inherently unordered in javascript, right?, so any name added to that property could potentially re-order the entries—could that lead to another resolution order?
Just wondering, as i couldn't find any documentation. it does become relevant when you do (and maybe you shouldn't) coffee --compile route/to/directory.
.js is loaded first (this also means that it's better to use full name.json for your fixture instead of name as it could be shadowed by name.js)
From "modules" documentation:
If the exact filename is not found, then node will attempt to load the required filename with the added extension of .js, .json, and then .node.
Also, read name resolution algorithm in pseudo-code:
LOAD_AS_FILE(X)
1. If X is a file, load X as JavaScript text. STOP
2. If X.js is a file, load X.js as JavaScript text. STOP
3. If X.node is a file, load X.node as binary addon. STOP
After (1,2,3) extensions set in require.extensions are checked in the order they a set (for CoffeScript, require("coffe-script") installs .coffee handler).
The behavior in V8 is to iterate over named properties in the order they were originally assigned, so I would expect .js to always be first.
This post references that behavior