toy-robot is a simulator of a toy robot that moves on a tabletop.
toy-robot reads instructions from STDIN, executing them one at a time until EOF is reached. (On a Linux or OSX system, type C-d to generate an EOF character).
| Ember.Application.initializer({ | |
| name: "storageService", | |
| initialize: function(container, application) { | |
| application.register('service:storage', application.StorageService, { | |
| singleton: true | |
| }); | |
| application.inject('route', 'storage', 'service:storage'); |
| init: function() { | |
| var callback = this._handleStorageEvent.bind(this); | |
| $(window).on('storage', callback); | |
| } | |
| _handleStorageEvent: function(event) { | |
| var storageEvent = event.originalEvent; | |
| var storageKey = storageEvent.key; | |
| var tokens = storageKey.split(':'); |
| setUnknownProperty: function(key, value) { | |
| var namespacedKey = this._key(key); | |
| var payload = this._serialize(value); | |
| this.get('persistence').setItem(namespacedKey, payload); | |
| this.notifyPropertyChange(key); | |
| return true; | |
| }, | |
| _serialize: function(value) { | |
| return JSON.stringify(value); |
| unknownProperty: function(key) { | |
| var namespacedKey = this._key(key); | |
| var payload = this.get('persistence').getItem(namespacedKey); | |
| return this._deserialize(payload); | |
| }, | |
| _deserialize: function(value) { | |
| return JSON.parse(value); | |
| }, |
| App.StorageService = Ember.Object.extend({ | |
| persistence: window.localStorage, | |
| namespace: 'ember-storage-service', | |
| // ... | |
| }); |
| function saveItem(key, value) { | |
| var json = JSON.stringify(value); | |
| localStorage.setItem(key, json); | |
| } | |
| function loadItem(key) { | |
| var json = localStorage.getItem(key); | |
| return JSON.parse(json); | |
| } |
| localStorage.setItem('numbers', [1, 2, 3]); | |
| localStorage.getItem('numbers') // => "1,2,3" | |
| var hash = { hello: 'world' } | |
| localStorage.setItem('myHash', hash); | |
| localStorage.getItem('myHash') // => "[object Object]" |
| if (!window.localStorage) { | |
| alert("Your browser doesn't support local storage!"); | |
| } | |
| // method based approach | |
| localStorage.setItem('textSize', 'giant'); | |
| localStorage.getItem('textSize'); // => "giant" | |
| // index accessor approach | |
| localStorage['selectedTab'] = 'preferences' |
| App.StorageService = Ember.Object.extend({ | |
| persistence: window.localStorage, | |
| namespace: 'ember-storage-service', | |
| init: function() { | |
| var callback = this._handleStorageEvent.bind(this); | |
| $(window).on('storage', callback); | |
| }, | |