I have part of typescript code
var root = window['appPath']
window.location.replace(root + '.... some url
Is the variable windows part of typescript? How do I assign it? Is it a key/value and what can I store in it?
Thanks
Is the variable windows part of typescript
Its a part of browser spec : http://www.w3schools.com/jsref/obj_window.asp
TypeScript defines these common globals for you in a file lib.d.ts : https://github.com/Microsoft/TypeScript/blob/master/bin/lib.d.ts
How do I assign it?
You shouldn't and actually browsers will not let you.
Is it a key/value and what can I store in it?
All JavaScript objects (I'm being lose here) act like key/value stores. The only allowed key is string. Value can be any other JavaScript object.
That said. DONT PUT STUFF ON WINDOW. MILLIONS OF KITTENS WILL DIE
Related
I'm currently trying to add scripting functionality to my C++ application by using v8. The goal is to process some data in buffers with JS and then return the result. I think I can generate an ArrayBuffer by using New with an appropriate BackingStore. The result would be a Local. I would now like to run scripts via v8::Script::Compile and v8::Script::Run. What would be the name of the ArrayBuffer - or how can I assign it a name so that it's accessible in the script? Do I need to make it a Globalif I need to run multiple scripts on the same ArrayBuffer?
If you want scripts to be able to access, say, my_array_buffer, then you'll have to install the ArrayBuffer as a property on the global object. See https://v8.dev/docs/embed for an introduction to embedding V8, and the additional examples linked from there. In short, it'll boil down to something like:
global_object->Set(context,
v8::String::NewFromUtf8(isolate, "my_array_buffer"),
array_buffer);
You don't need to store the ArrayBuffer in a Global for this to work.
I a developing a macOS commandline application in Xcode, which uses User Defaults. I have the following code for my User Defaults
if let configDefaults = UserDefaults.init(suiteName: "com.tests.configuration") {
configDefaults.set("myStringValue", forKey: "stringKey")
configDefaults.synchronize()
print(configDefaults.dictionaryRepresentation())
}
This will create my own .plist file in the ~/Library/Preferences folder. If I look into the file, I can see only my single value which I added, which is perfectly fine. But when I call dictionaryRepresentation() on my UserDefaults object, the there are a lot of other attributes (I guess from the shared UserDefaults object), like
com.apple.trackpad.twoFingerFromRightEdgeSwipeGesture or AKLastEmailListRequestDateKey
Looking into the documentation of UserDefaults, it seems that this has to do with the search list of UserDefaults and that the standard object is in the search list:
func dictionaryRepresentation() -> [String : Any]
Returns a dictionary that contains a union of all key-value pairs in the domains in the search list.
There are also the methods addSuite and removeSuite for a UserDefaults object, so I am guessing I need to remove the .standard suite from my configDefaults object, but I don't know the name, which should be used for that in the method.
Is it possible to remove the .standard defaults from the dictionary representation? I basically just want all of my own data in a dictionary, nothing more.
The reason I am trying to get only my values from the UserDefaults, is that a have a number of object of a custom type Connection (which store the configuration to connect to a server), which are saved in the UserDefaults. On program start I want to be able to load all objects into my app. Therefore I thought I could use dictionaryRepresentation(), as it would return all elements in the UserDefaults. But then there should be only my Connection objects in the dictionary, so that I can cast it to [String: Connection].
Given your purpose (in your latest edit of your question), what you should do is store a collection of Connection objects under a single key. Then, look up that key to get the collection.
It's not clear if the collection should be an array of Connection objects or a dictionary mapping strings to Connections. That's a choice you can make.
But, in any case, you shouldn't rely on the defaults being empty of everything else.
In other words, you would do:
UserDefaults.standard.set(yourStringToConnectionDictionary, forKey:"yourSingleKey")
and later:
let connectionMap = UserDefaults.dictionary(forKey:"yourSingleKey")
then look up Connections in the connectionMap by their name/ID/whatever.
Though the other solution proposed by Ken Thomases may be better from a design standpoint, I've found a solution that does exactly what I initially wanted. Calling
UserDefaults.standard.persistentDomain(forName: "com.company.TestApp.configuration")
Returns a dictionary containing only the values I've added to the domain com.company.TestApp.configuration, using
let configs = UserDefaults.init(suiteName: "com.company.TestApp.configuration")!
configs.set(someData, forKey: someKey)
Strangely in the Apple documentation says this about persistentDomain(forName:):
Calling this method is equivalent to initializing a user defaults object with init(suiteName:) passing domainName and calling the dictionaryRepresentation() method on it.
But this is not the case (see my question). Clarification on that subject is more than welcome.
I have an object with a variable containing a String.
I have a window containing a LabelMorph/TextMorph (or some other Morph that displays Text?).
How do i bind the LabelMorph/TextMorph to the variable, so that the label updates when the String in the variable changes?
classic Smalltalk-80 dependent/change/update mechanism?
Pharo Announcement framework?
something different??
How would i do this? Which Morph should i use?
Simplest is to use an updating String morph:
UpdatingStringMorph on: self selector: #myLabel
This will send #myLabel (or any other message) to self (or any other object) and display it.
This is a solution provided by Benjamin Van Ryseghem on the Pharo Mailinglist:
For this kind of situation, my solution is to use a ValueHolder.
Instead of storing your string directly in an instance variable, store
it into the ValueHolder.
I tried this in a Workspace:
|string label|
string := 'Wait till i change..' asValueHolder.
label := LabelMorph contents: string contents.
string whenChangedDo: [:newValue | label contents: newValue ].
label openInWindow.
[ 5 seconds asDelay wait. string value: 'I changed :)' ] fork.
Depends on what you want to achieve.
You might want to take a look at a way to do it with Glamour in a current Moose image.
In a workspace, do-it:
GLMBasicExamples new magritte openOn: GLMMagrittePersonExample sampleData
That shows how to work with announcements on save. The earlier examples are a better way to start understanding how to work with Glamour (and because of the way the examplebrowser is build, the Magritte example doesn't update the list when it is nested):
GLMBasicExamples open
That has several other examples that update on change.
I am trying to learn symfony framework by creating a small project.
Since I started developing the project I have been wondering if there is a convenience function to see the contents or information of a variable or array anywherea in the application by print_r or echo or var_dump (I can use the aforesaid function straight away anywhere in the application but the output is not properly readable in case of large arrays, moreover there are warnings showin like header already sent etc. etc.).
I have also used cakePHP and it has a convenience function named pr() which prints out the contents of variable or array nicely indented (properly readable).
If I had to create such function than how can I make sure that it can be called anywhere in the application?
Any tips (links/blogs/tutorials) related to "how to debug your symfony applications" are greatly appreciated.
To put it simple: you can't output debug "things" in your controller. The controller has nothing to do with the View (output), so when executing it does not know if there's going to be any output.
But, you can output debug "things" in your controller ;-)...
Just print_r() or var_dump(). And immediately die afterwards. That way you can see your debugging.
Call the logger. $this->getLogger()->debug($message);
Add a custom slot which you assign in your controller ($this->getResponse()->setSlot('debug', $debugData)). And include this slot somewhere in your layout file (preferably only in the dev environment.)
I have an addon that every 5 minuets or so checks an rss feed for a new post, and if there is one, it displays an alert(). Problem is, I'm afraid that if the user opens multiple windows, that when there's a new post a millions of alerts will popup saying the same thing. Is there anyway to have just one "brain" running at a time?
Thanks in advance!
Look up something called "Javascript shared code modules" or JSMs.
Primary docs are here:
https://developer.mozilla.org/En/Using_JavaScript_code_modules
Each .js file in your addon that needs shared memory will open with the following line:
Components.utils.import("resource://xxxxxxxx/modules/[yourFilenameHere].jsm", com.myFirefoxAddon.shared);
The above line opens [yourFilenameHere].jsm and loads its exported (see below) functions and variables into the com.myFirefoxAddon.shared object. Each instance of that object loaded will point to the same instance in memory.
Note that if you want to have any hope of you addon making it past moderation, you will need to write all your code in a com.myFirefoxAddon.* type object as the goons at AMO are preventing approval of addons that do not Respect the Global Namespace
The biggest caveat for JSM is that you need to manually export each function that you want to be available to the rest of your code... since JS doesn't support public/private type stuff this strikes me as a sort of poor-man's "public" support... in any case, you will need to create an EXPORTED_SYMBOLS array somewhere in your JSM file and name out each function or object that you want to export, like this:
var EXPORTED_SYMBOLS = [
/* CONSTANTS */
"SERVER_DEBUG",
"SERVER_RELEASE",
"LIST_COUNTRIES",
"LIST_TERRITORIES_NOEX",
/* GLOBAL VARIABLES */
/* note: primitive type variables need to be stored in the globals object */
"urlTable",
"globals",
/* INTERFACES */
"iStrSet",
/* FUNCTIONS */
"globalStartup",
/* OBJECTS */
"thinger",
"myObject"
]
[edited] Modules are not the right solution to this problem, since the code will still be imported into every window and the whatever listeners/timers you set up will run in every window. You should be careful with using modules for this -- all the timers/callbacks must be set up in the module code (not just using the observer object defined in the module) and you shouldn't use any references to the window in the module.
The right way to do this is I would prefer to write an XPCOM component (in JS). It's somewhat complicated, yes and I don't have a handy link explaining how to do it. One thing: implementing it using XPCOMUtils is easier, older documentation will throw lots of boilerplate code on you.