Skip to content

Commit fc62c0e

Browse files
committed
* Use tilde-property syntax from Coco; @Nami-Doc++
1 parent 7c53c18 commit fc62c0e

File tree

2 files changed

+83
-76
lines changed

2 files changed

+83
-76
lines changed

sc.js

Lines changed: 68 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -147,64 +147,76 @@
147147
? elems
148148
: [];
149149
this.raw = raw != null ? raw : '';
150-
Object.defineProperty(this, 'id', {
151-
set: function(it){
152-
return this.attrs.id = it;
153-
}
154-
});
155-
Object.defineProperty(this, 'width', {
156-
set: function(it){
157-
return this.attrs.width = it;
158-
}
159-
});
160-
Object.defineProperty(this, 'height', {
161-
set: function(it){
162-
return this.attrs.height = it;
163-
}
164-
});
165-
Object.defineProperty(this, 'className', {
166-
set: function(it){
167-
return this.attrs['class'] = it;
168-
}
169-
});
170-
Object.defineProperty(this, 'innerHTML', {
171-
get: function(){
172-
return this.raw || join$.call(this.elems.map(function(it){
173-
return it.outerHTML;
174-
}), "\n");
175-
},
176-
set: function(it){
177-
return this.raw = it;
178-
}
179-
});
180-
Object.defineProperty(this, 'outerHTML', {
181-
get: function(){
182-
var tag, attrs, style, k, v, css;
183-
tag = this.tag, attrs = this.attrs, style = this.style;
184-
css = style.cssText || (function(){
185-
var ref$, results$ = [];
186-
for (k in ref$ = style) {
187-
v = ref$[k];
188-
results$.push(k + ":" + v);
189-
}
190-
return results$;
191-
}()).join(";");
192-
if (css) {
193-
attrs.style = css;
194-
} else {
195-
delete attrs.style;
150+
}
151+
Object.defineProperty(prototype, 'id', {
152+
set: function(id){
153+
this.attrs.id = id;
154+
},
155+
configurable: true,
156+
enumerable: true
157+
});
158+
Object.defineProperty(prototype, 'width', {
159+
set: function(width){
160+
this.attrs.width = width;
161+
},
162+
configurable: true,
163+
enumerable: true
164+
});
165+
Object.defineProperty(prototype, 'height', {
166+
set: function(height){
167+
this.attrs.height = height;
168+
},
169+
configurable: true,
170+
enumerable: true
171+
});
172+
Object.defineProperty(prototype, 'className', {
173+
set: function($class){
174+
this.attrs['class'] = $class;
175+
},
176+
configurable: true,
177+
enumerable: true
178+
});
179+
Object.defineProperty(prototype, 'innerHTML', {
180+
set: function(raw){
181+
this.raw = raw;
182+
},
183+
get: function(){
184+
return this.raw || join$.call(this.elems.map(function(it){
185+
return it.outerHTML;
186+
}), "\n");
187+
},
188+
configurable: true,
189+
enumerable: true
190+
});
191+
Object.defineProperty(prototype, 'outerHTML', {
192+
get: function(){
193+
var tag, attrs, style, k, v, css;
194+
tag = this.tag, attrs = this.attrs, style = this.style;
195+
css = style.cssText || (function(){
196+
var ref$, results$ = [];
197+
for (k in ref$ = style) {
198+
v = ref$[k];
199+
results$.push(k + ":" + v);
196200
}
197-
return "<" + tag + (function(){
198-
var ref$, results$ = [];
199-
for (k in ref$ = attrs) {
200-
v = ref$[k];
201-
results$.push(" " + k + "=\"" + v + "\"");
202-
}
203-
return results$;
204-
}()).join("") + ">" + this.innerHTML + "</" + tag + ">";
201+
return results$;
202+
}()).join(";");
203+
if (css) {
204+
attrs.style = css;
205+
} else {
206+
delete attrs.style;
205207
}
206-
});
207-
}
208+
return "<" + tag + (function(){
209+
var ref$, results$ = [];
210+
for (k in ref$ = attrs) {
211+
v = ref$[k];
212+
results$.push(" " + k + "=\"" + v + "\"");
213+
}
214+
return results$;
215+
}()).join("") + ">" + this.innerHTML + "</" + tag + ">";
216+
},
217+
configurable: true,
218+
enumerable: true
219+
});
208220
prototype.appendChild = function(it){
209221
return this.elems.push(it);
210222
};

src/sc.ls

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,19 @@ global.SC ?= {}
9494
return SC
9595

9696
class Node
97-
(@tag="div", @attrs={}, @style={}, @elems=[], @raw='') ->
98-
Object.defineProperty @, \id do
99-
set: -> @attrs.id = it
100-
Object.defineProperty @, \width do
101-
set: -> @attrs.width = it
102-
Object.defineProperty @, \height do
103-
set: -> @attrs.height = it
104-
Object.defineProperty @, \className do
105-
set: -> @attrs.class = it
106-
Object.defineProperty @, \innerHTML do
107-
get: -> @raw or (@elems.map -> it.outerHTML) * "\n"
108-
set: -> @raw = it
109-
Object.defineProperty @, \outerHTML do
110-
get: ->
111-
{tag, attrs, style} = @
112-
css = style.cssText or [ "#k:#v" for k, v of style ] * ";"
113-
if css then attrs.style = css else delete attrs.style
114-
return "<#tag#{
115-
[ " #k=\"#v\"" for k, v of attrs ] * ""
116-
}>#{ @innerHTML }</#tag>"
97+
(@tag="div", @attrs={}, @style={}, @elems=[], @raw='')->
98+
id: ~(@attrs.id)->
99+
width: ~(@attrs.width)->
100+
height: ~(@attrs.height)->
101+
className: ~(@attrs.class)->
102+
innerHTML: ~
103+
(@raw)->
104+
-> @raw or (@elems.map -> it.outerHTML) * "\n"
105+
outerHTML: ~->
106+
{tag, attrs, style} = @
107+
css = style.cssText or [ "#k:#v" for k, v of style ] * ";"
108+
if css then attrs.style = css else delete attrs.style
109+
return "<#tag#{
110+
[ " #k=\"#v\"" for k, v of attrs ] * ""
111+
}>#{ @innerHTML }</#tag>"
117112
appendChild: -> @elems.push it

0 commit comments

Comments
 (0)