-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from emberjs/string-module
Extracts code from Ember and sets minimum ember-cli-babel
- Loading branch information
Showing
28 changed files
with
6,117 additions
and
6,927 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# 1.0.0 | ||
|
||
## `fmt` | ||
### until: 2.0.0 | ||
### id: ember-string-fmt | ||
|
||
This utility was included to ease the transition from the | ||
internal Ember string package to this addon. | ||
We suggest that you update your code to use [ES2015 template strings](http://babeljs.io/docs/learn-es2015/#template-strings). | ||
|
||
For example, if you have the following `fmt` uses: | ||
|
||
```javascript | ||
import { fmt } from "@ember/string"; | ||
|
||
let firstName = "John"; | ||
let lastName = "Doe"; | ||
|
||
fmt("Hello %@ %@", firstName, lastName); // "Hello John Doe" | ||
fmt("Hello %@2, %@1", firstName, lastName); // "Hello Doe, John" | ||
``` | ||
|
||
You can instead use the following template strings: | ||
|
||
```javascript | ||
import { fmt } from "@ember/string"; | ||
|
||
let firstName = "John"; | ||
let lastName = "Doe"; | ||
|
||
`Hello ${firstName} ${lastName}` // "Hello John Doe" | ||
`Hello ${lastName}, ${firstName}` // "Hello Doe, John" | ||
``` | ||
|
||
|
||
## `loc` | ||
### until: 2.0.0 | ||
### id: ember-string-loc | ||
|
||
This utility was included to ease the transition from the | ||
internal Ember string package to this addon. | ||
You can consult the [Ember deprecation guide for loc](https://emberjs.com/deprecations/v2.x#toc_code-ember-string-loc-code-and-code-import-loc-from-ember-string-code) for further | ||
instructions on how to update your code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const UNDEFINED = function() {} | ||
|
||
export default class Cache { | ||
constructor(limit, func, key, store) { | ||
this.size = 0; | ||
this.misses = 0; | ||
this.hits = 0; | ||
this.limit = limit; | ||
this.func = func; | ||
this.key = key; | ||
this.store = store || new DefaultStore(); | ||
} | ||
|
||
get(obj) { | ||
let key = this.key === undefined ? obj : this.key(obj); | ||
let value = this.store.get(key); | ||
if (value === undefined) { | ||
this.misses ++; | ||
value = this._set(key, this.func(obj)); | ||
} else if (value === UNDEFINED) { | ||
this.hits ++; | ||
value = undefined; | ||
} else { | ||
this.hits ++; | ||
// nothing to translate | ||
} | ||
|
||
return value; | ||
} | ||
|
||
set(obj, value) { | ||
let key = this.key === undefined ? obj : this.key(obj); | ||
return this._set(key, value); | ||
} | ||
|
||
_set(key, value) { | ||
if (this.limit > this.size) { | ||
this.size ++; | ||
if (value === undefined) { | ||
this.store.set(key, UNDEFINED); | ||
} else { | ||
this.store.set(key, value); | ||
} | ||
} | ||
|
||
return value; | ||
} | ||
|
||
purge() { | ||
this.store.clear(); | ||
this.size = 0; | ||
this.hits = 0; | ||
this.misses = 0; | ||
} | ||
} | ||
|
||
class DefaultStore { | ||
constructor() { | ||
this.data = Object.create(null); | ||
} | ||
|
||
get(key) { | ||
return this.data[key]; | ||
} | ||
|
||
set(key, value) { | ||
this.data[key] = value; | ||
} | ||
|
||
clear() { | ||
this.data = Object.create(null); | ||
} | ||
} |
Oops, something went wrong.